jdbcTemplate测试报错:没有合适的驱动
報錯具體信息:
"C:\Program Files\Java\jdk1.8.0_201\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\idea\IntelliJ IDEA 2020.2.1\lib\idea_rt.jar=57710:D:\idea\IntelliJ IDEA 2020.2.1\bin" -Dfile.encoding=UTF-8 -classpath "D:\idea\IntelliJ IDEA 2020.2.1\lib\idea_rt.jar;D:\idea\IntelliJ IDEA 2020.2.1\plugins\junit\lib\junit5-rt.jar;D:\idea\IntelliJ IDEA 2020.2.1\plugins\junit\lib\junit-rt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_201\jre\lib\rt.jar;D:\idea\jdbcDemo\untitled1\target\test-classes;D:\idea\jdbcDemo\untitled1\target\classes;D:\apache-maven-3.6.1-bin\apache-maven-3.6.1\Maven-respostory\junit\junit\4.11\junit-4.11.jar;D:\apache-maven-3.6.1-bin\apache-maven-3.6.1\Maven-respostory\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\apache-maven-3.6.1-bin\apache-maven-3.6.1\Maven-respostory\mysql\mysql-connector-java\5.1.17\mysql-connector-java-5.1.17.jar;D:\apache-maven-3.6.1-bin\apache-maven-3.6.1\Maven-respostory\org\springframework\spring-core\4.3.17.RELEASE\spring-core-4.3.17.RELEASE.jar;D:\apache-maven-3.6.1-bin\apache-maven-3.6.1\Maven-respostory\org\springframework\spring-beans\4.3.17.RELEASE\spring-beans-4.3.17.RELEASE.jar;D:\apache-maven-3.6.1-bin\apache-maven-3.6.1\Maven-respostory\org\springframework\spring-jdbc\4.3.17.RELEASE\spring-jdbc-4.3.17.RELEASE.jar;D:\apache-maven-3.6.1-bin\apache-maven-3.6.1\Maven-respostory\org\springframework\spring-tx\4.3.17.RELEASE\spring-tx-4.3.17.RELEASE.jar;D:\apache-maven-3.6.1-bin\apache-maven-3.6.1\Maven-respostory\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\apache-maven-3.6.1-bin\apache-maven-3.6.1\Maven-respostory\com\mchange\c3p0\0.9.5.2\c3p0-0.9.5.2.jar;D:\apache-maven-3.6.1-bin\apache-maven-3.6.1\Maven-respostory\com\mchange\mchange-commons-java\0.2.11\mchange-commons-java-0.2.11.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 StudentTest,test
十二月 26, 2020 9:34:29 下午 com.mchange.v2.log.MLog?
信息: MLog clients using java 1.4+ standard logging.
十二月 26, 2020 9:34:29 下午 com.mchange.v2.c3p0.C3P0Registry?
信息: Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
十二月 26, 2020 9:34:29 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource?
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hge1dbae186s3k91m7wdey|2db0f6b2, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> null, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge1dbae186s3k91m7wdey|2db0f6b2, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> null, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
十二月 26, 2020 9:34:59 下午 com.mchange.v2.resourcepool.BasicResourcePool?
警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@327339f3 -- 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: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)
十二月 26, 2020 9:34:59 下午 com.mchange.v2.resourcepool.BasicResourcePool?
警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@4acae9ba -- 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: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)
十二月 26, 2020 9:34:59 下午 com.mchange.v2.resourcepool.BasicResourcePool?
警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@4d41cee is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
十二月 26, 2020 9:34:59 下午 com.mchange.v2.resourcepool.BasicResourcePool?
警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@4d41cee is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
十二月 26, 2020 9:34:59 下午 com.mchange.v2.resourcepool.BasicResourcePool?
警告: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@388b5283 -- 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: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)
十二月 26, 2020 9:34:59 下午 com.mchange.v2.resourcepool.BasicResourcePool?
警告: Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool@4d41cee is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
?? ?at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
?? ?at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:394)
?? ?at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:478)
?? ?at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:488)
?? ?at util.StudentDaoImpl.queryAllStudents(StudentDaoImpl.java:56)
?? ?at StudentTest.test(StudentTest.java:14)
?? ?at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
?? ?at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
?? ?at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
?? ?at java.lang.reflect.Method.invoke(Method.java:498)
?? ?at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
?? ?at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
?? ?at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
?? ?at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
?? ?at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
?? ?at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
?? ?at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
?? ?at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
?? ?at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
?? ?at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
?? ?at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
?? ?at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
?? ?at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
?? ?at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
?? ?at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
?? ?at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
?? ?at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
?? ?at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
?? ?at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
?? ?at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:692)
?? ?at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
?? ?at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
?? ?at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
?? ?... 27 more
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:1469)
?? ?at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
?? ?at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
?? ?at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
?? ?at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
?? ?... 30 more
Caused by: 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)
Process finished with exit code -1
?
報錯原因:創建的不是JavaWeb項目
?
解決方法:創建JavaWeb項目并遷移代碼
1.創建JavaWeb項目
File-New-Project-Maven-勾選Create from archetype-選擇webapp-next
根據自己的項目填寫信息,注意Maven目錄的填寫
2.解決pom依賴
把原項目pom文件中的dependency復制到新項目的pom文件中,并刷新新項目的maven jar包,能看到dependencies出現了需要的包
3.遷移代碼和配置文件
Com.hisoft.pojo存放實體類Student
Com.hisoft.dao進行數據庫交互
Com.hisoft.utils是工具類
C3p3-config.xml放在main/resource中
4.運行測試代碼
?
?
成功ヾ(?°?°?)ノ゙
其實這個挺憨憨的,項目類型創建錯了
如果出現問題,可以根據報錯提示進行查找,常見的問題有:
1.c3p0配置文件沒有放在src下面
2.數據庫最大連接數不夠,修改mysql的最大連接數
查看最大連接數:
show variables like '%max_connections%'
修改最大連接數據:
set global max_connections=1000
3.換jdbc的驅動jar包
查看mysql版本命令:show variables like '%version%'
4.配置文件地址不對,配置文件中的換連接地址
5.數據庫連接密碼錯了
6.項目類型創建錯誤
?
總結
以上是生活随笔為你收集整理的jdbcTemplate测试报错:没有合适的驱动的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 环形队列出队的元素怎么输出出来_队列的知
- 下一篇: Docker中未指定挂载点容器间volu