回答1:
java
spring 加載數據庫鏈接驅動的時候出現找不到驅動類解決辦法。mysql
com.mchange.v2.c3p0.DriverManagerDataSourceensureDriverLoadedspring
1, 首先肯定是否有相應的驅動包sql
2, 查看配置數據庫鏈接文件每行的末尾是否有空格。數據庫
回答2:apache
1.0 配置c3p0數據源,一直提示 沒法加載數據庫驅動。app
可是明明有驅動,很是疑惑。。。。。async
com.mchange.v2.c3p0.DriverManagerDataSource ---- Could not load driverClass com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1311)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1145)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:112)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:144)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
com.mchange.v2.c3p0.DriverManagerDataSource ---- Could not load driverClass com.mysql.jdbc.Driver post
仔細觀察,木有任何問題,他麼的 ,水缸裏還能把王八跑了?ui
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!-- 初始化創建的鏈接數 -->
<property name="initialPoolSize" value="10"/>
<!-- 最大空閒時間,120秒內未被使用的鏈接將被丟棄 -->
<property name="maxIdleTime" value="120"/>
<!-- 當鏈接池耗盡,且未達到最大鏈接數時,一次獲取的鏈接數 -->
<property name="acquireIncrement" value="2"/>
<!-- 空閒檢查時間間隔, 每隔120秒檢查鏈接池裏的空閒鏈接 ,單位是秒 -->
<property name="idleConnectionTestPeriod" value="60"/>
</bean>
3.0查看jdbc.properties
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost\:3306/dftsms?useUnicode\=true&characterEncoding\=UTF8
jdbc.username=root
jdbc.password=1234
jdbc.initialPoolSize=10
jdbc.maxIdleTime=120
jdbc.acquireIncrement=2
jdbc.idleConnectionTestPeriod=60
仔仔細細看完,木有任何問題啊 ,這他麼怎麼回事兒。。。。。。
最後,通過多方查證,馬丹,原來是jdbc.properties 文件中jdbc.driverClassName=com.mysql.jdbc.Driver,這一句配置 後面有個空格。。。。。。。
問題很噁心,結果很尷尬。。。。