c3p0数据库连接不上

在写一个Javaweb 项目时,在数据库连接的地方出错(用的c3p0)

java.sql.SQLException: No suitable driver
	at java.sql.DriverManager.getDriver(DriverManager.java:315)
	at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:161)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:161)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:147)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:202)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
	at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
	at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
	at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

搜了好多网上的资料,依然无法解决

结果发现是resouces不是一个根目录,而是一个普通的包造成的,只需要按下图把它变成一个根目录即可

c3p0数据库连接不上_第1张图片

结果正确

c3p0数据库连接不上_第2张图片

如果还没有解决,可以考虑以下原因

1.数据库驱动包是否不符

2.jdbc连接URL格式出现了问题

3.com.mysql.jdbc.driver(mysql5)

com.mysql.cj.jdbc.driver(mysql8.0)

4.把c3p0-config.xml文件放到java目录下

 

你可能感兴趣的:(c3p0数据库连接不上)