回答1:
spring 加载数据库连接驱动的时候出现找不到驱动类解决办法。
com.mchange.v2.c3p0.DriverManagerDataSourceensureDriverLoaded
1, 首先确定是否有相应的驱动包
2, 查看配置数据库连接文件每行的末尾是否有空格。
回答2:
1.0 配置c3p0数据源,一直提示 无法加载数据库驱动。
但是明明有驱动,非常疑惑。。。。。
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
仔细观察,木有任何问题,他么的 ,水缸里还能把王八跑了?
<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,这一句配置 后面有个空格。。。。。。。
问题很恶心,结果很尴尬。。。。