纯JDBC配置C3P0 sqlserver数据库 连接就报错!

发布于 2021-11-21 18:15:39 字数 8196 浏览 744 评论 5

我就简单的写了个纯的JDBC配置C3P0竟然出错了,我自己都没想得到会出错

给大家看一下我的配置吧,很简单的,这种配置我改成oracle的数据库就OK一换成sqlserver的就报错了,自己就也不知道为什么,难道两者有什么差异?求教!

C3P0配置:

<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
		<default-config>
				<property name="user">sa</property>
				<property name="password">qaz123</property>
				<property name="driverClass">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
				<property name="jdbcUrl">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ZCPD</property>
				<property name="initialPoolSize">20</property>
				<property name="maxIdleTime">50</property>
				<property name="maxPoolSize">30</property>
				<property name="minPoolSize">10</property>
		</default-config>
</c3p0-config>



获取连接对象代码:

public class C3P0Utils {
		private C3P0Utils(){}
		private static  ComboPooledDataSource ds=null;
		static{
				try {
					ds=new ComboPooledDataSource();
				} catch (Exception e) {
					e.printStackTrace();
				}
		}
		public static Connection getConnection(){
				Connection conn=null;
				try {
					conn=ds.getConnection();
				} catch (Exception e) {
					e.printStackTrace();
				}
				return conn;
		}
}



我写了个main方法输出这个conn就报错了!

另外我的用户名、密码都是OK的,服务也启动

报错信息:

Managed Threads: 3
	Active Threads: 3
	Active Tasks: 
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1cf4a2c (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@eac5a (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@15575e0 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
	Pending Tasks: 
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1addb59
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@11bed71
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@81b1fb
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@cbdb20
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@19f3736
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1e1dadb
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@e79839
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@bac9b9
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@111b910
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@8ceeea
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@995a79
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2c35e
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1687e7c
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@14835fb
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1cffeb4
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@5b0668
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1d5a0
Pool thread stack traces:
	Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
		java.lang.Thread.sleep(Native Method)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
		com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
	Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
		java.lang.Thread.sleep(Native Method)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
		com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
	Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
		java.lang.Thread.sleep(Native Method)
		com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
		com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)


2014-5-18 11:10:34 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1cf4a2c -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
java.sql.SQLException: No suitable driver
	at java.sql.DriverManager.getDriver(DriverManager.java:264)
	at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
	at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
	at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
	at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
java.sql.SQLException: Connections could not be acquired from the underlying database!
	at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
	at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
	at com.ft.utils.C3P0Utils.getConnection(C3P0Utils.java:20)
	at com.ft.utils.TEST.main(TEST.java:5)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
	at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
	at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
	at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
	... 3 more
2014-5-18 11:10:34 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@eac5a -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
java.sql.SQLException: No suitable driver
	at java.sql.DriverManager.getDriver(DriverManager.java:264)
	at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
	at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
	at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
	at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)



如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

醉酒的小男人 2021-11-25 14:58:02

我2年来一直都用的这个驱动包,想不通

永不分离 2021-11-25 14:57:56

回复
你帖的报错里这么说,也有可能是没找到还是怎么

彼岸花ソ最美的依靠 2021-11-25 14:49:24

建议采用jtds来进行驱动。

岁月打碎记忆 2021-11-25 11:55:03

java.sql.SQLException: No suitable driver

没选对驱动?

冬天旳寂寞 2021-11-23 12:28:17

解决了!又是小毛病!自己都悔恨呐!

sqlserver连接的URL和驱动类分2003和2005,我当时注意到这点了,但是我驱动类写对了,但是URL写成2003的了,我用的是2008,所以就报错了!

唉,自己总是不注意太粗心,大家以后可不能像我这样!谨记!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文