关于java.sql.SQLException: No suitable driver问题的解决

最近写一个小程序时遇到的问题:我是用c3p0连接池进行数据库连接、myeclipse2014环境中导入的eclipse的项目、在c3p0配置文件(c3p0-config.xml)中配置如下:


	
		
			com.mysql.jdbc.Driver
			jdbc\:mysql\://172.1.1.1\:3306/ssms
			root
			Admin_123
		
	
	

在Tomcat7.0下部署、然后启动Tomcat后报错如下:

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)
报错异常提示是说:没有合适的驱动;其实不然,网上查了一下很多原因不在于驱动的问题,而是jdbcUrl有问题,我就是如此,正确如下:

jdbc:mysql://172.1.1.1:3306/ssms
多写了转义反斜杠"\"。

当然还有其他情况也不排除:

比如:驱动name写错(driverClass写成DriverClassName)、URL的name写错(jdbcUrl写成url)、或者真的是没有加载jdbc驱动包导致

最后提醒各位码农同胞们,一定要仔细点哈!



你可能感兴趣的:(Database,(Mysql-Oracle))