Solution to the problem of java.sql.SQLException: No suitable driver

Keywords: Java JDBC MySQL xml

Recent problems encountered in writing a small program: I use the c3p0 connection pool for database connection, the project of eclipse imported in MyEclipse 2014 environment, and configure it in the c3p0 configuration file (c3p0-config.xml) as follows:

<?xml version="1.0" encoding="UTF-8"?>
	<c3p0-config>
		<default-config>
			<property name="driverClass">com.mysql.jdbc.Driver</property>
			<property name="jdbcUrl">jdbc\:mysql\://172.1.1.1\:3306/ssms</property>
			<property name="user">root</property>
			<property name="password">Admin_123</property>
		</default-config>
	
	</c3p0-config>

After deploying under Tomcat 7.0 and starting Tomcat, the following error is reported:

java.sql.SQLException: No suitable driver
 at java.sql.DriverManager.getDriver(Unknown Source)
 at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:144)
 at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:68)
 at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:87)
 at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.acquireResource(C3P0PooledConnectionPool.java:83)
 at com.mchange.v2.resourcepool.BasicResourcePool.assimilateResource(BasicResourcePool.java:884)
 at com.mchange.v2.resourcepool.BasicResourcePool.acquireUntil(BasicResourcePool.java:601)
 at com.mchange.v2.resourcepool.BasicResourcePool.access$400(BasicResourcePool.java:31)
 at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1079)
 at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:354)
The error-reporting exception hint is that there is no suitable driver; otherwise, many reasons are not the driver problem, but the jdbcUrl problem. That's what I am doing. The correct answer is as follows:

<property name="jdbcUrl">jdbc:mysql://172.1.1.1:3306/ssms</property>
Write more escape backslash "".

Of course, there are other situations which are not excluded:

For example: driverClass is written as DriverClassName, the name of the URL is written as url, or really the result of not loading the jdbc driver package.

Finally, I would like to remind you, fellow farmers, that you must be careful.



Posted by jumphopper on Tue, 12 Feb 2019 07:42:17 -0800