junit运行错误

junit运行错误

com.mchange.v2.cfg.DelayedLogItem [ level -> FINE, text -> "The configuration file for resource identifier '/mchange-commons.properties' could not be found. Skipping.", exception -> null]

com.mchange.v2.cfg.DelayedLogItem [ level -> FINE, text -> "The configuration file for resource identifier '/mchange-log.properties' could not be found. Skipping.", exception -> null]

com.mchange.v2.cfg.DelayedLogItem [ level -> FINE, text -> "The configuration file for resource identifier '/c3p0.properties' could not be found. Skipping.", exception -> null]

十月 14, 2019 3:35:42 下午 com.mchange.v2.log.MLog 

信息: MLog clients using java 1.4+ standard logging.

十月 14, 2019 3:35:42 下午 com.mchange.v2.c3p0.C3P0Registry 

信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]

十月 14, 2019 3:35:42 下午 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, dataSourceName -> 1hgeye8a51jto8km12jm0c0|54174e5, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hgeye8a51jto8km12jm0c0|54174e5, idleConnectionTestPeriod -> 0, initialPoolSize -> 5, jdbcUrl -> jdbc:mysql:///jdbctest, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]

十月 14, 2019 3:36:02 下午 com.mchange.v2.async.ThreadPoolAsynchronousRunner 

警告: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@619988c4 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!

十月 14, 2019 3:36:02 下午 com.mchange.v2.async.ThreadPoolAsynchronousRunner 

警告: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@619988c4 -- APPARENT DEADLOCK!!! Complete Status: 

Managed Threads: 3

Active Threads: 3

Active Tasks: 

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@6a39579

on thread: com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@5daa3e56

on thread: com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@53e2b024

on thread: com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1

Pending Tasks: 

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@479a3682

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@5d70b587

Pool thread stack traces:

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:696)

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:696)

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:696)


十月 14, 2019 3:36:13 下午 com.mchange.v2.resourcepool.BasicResourcePool 

警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@6a39579 -- 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: Unknown system variable 'tx_isolation'

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)

at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)

at com.mysql.jdbc.ConnectionImpl.getTransactionIsolation(ConnectionImpl.java:3131)

at com.mchange.v2.c3p0.impl.NewPooledConnection.<init>(NewPooledConnection.java:107)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:198)

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:696)


十月 14, 2019 3:36:13 下午 com.mchange.v2.resourcepool.BasicResourcePool 

警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@53e2b024 -- 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: Unknown system variable 'tx_isolation'

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)

at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)

at com.mysql.jdbc.ConnectionImpl.getTransactionIsolation(ConnectionImpl.java:3131)

at com.mchange.v2.c3p0.impl.NewPooledConnection.<init>(NewPooledConnection.java:107)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:198)

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:696)


十月 14, 2019 3:36:13 下午 com.mchange.v2.resourcepool.BasicResourcePool 

警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@5daa3e56 -- 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: Unknown system variable 'tx_isolation'

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)

at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)

at com.mysql.jdbc.ConnectionImpl.getTransactionIsolation(ConnectionImpl.java:3131)

at com.mchange.v2.c3p0.impl.NewPooledConnection.<init>(NewPooledConnection.java:107)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:198)

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:696)


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:529)

at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)

at com.imooc.jdbc.utils.JDBCUtils2.getConnection(JDBCUtils2.java:25)

at com.imooc.jdbcdemo1.JDBCP30.demo2(JDBCP30.java:67)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

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)

... 26 more



@Test

public void demo2(){

Connection connection=null;

PreparedStatement preparedStatement=null;

ResultSet rs=null;

try {

ComboPooledDataSource dataSource=new ComboPooledDataSource();

connection=JDBCUtils2.getConnection();

String sql="select * from user";

preparedStatement=connection.prepareStatement(sql);

rs=preparedStatement.executeQuery();

while(rs.next()){

int id = rs.getInt("id");

String name = rs.getString("name");

String category = rs.getString("category");

Date createTime = rs.getDate("createTime");


System.out.println(id + " " + name + " " + category + 

" " + createTime);

}


} catch (Exception e) {

// TODO 自动生成的 catch 块

e.printStackTrace();

}finally {

JDBCUtils2.release(rs,preparedStatement,connection);

}

}



<?xml version="1.0" encoding="UTF-8"?>

<c3p0-config>

<!--配置连接池mysql-->

<default-config > 

<property name="driverClass">com.mysql.jdbc.Driver</property> 

<property name="jdbcUrl">jdbc:mysql:///jdbctest</property> 

<property name="user">root</property> 

<property name="password">root</property> 

<property name="initialPoolSize">5</property> 

<property name="maxPoolSize">20</property> 

</default-config> 


</c3p0-config>

package com.imooc.jdbc.utils;


import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;


import com.mchange.v2.c3p0.ComboPooledDataSource;


/**

 * 

 * jdbc的工具类

 * 

 * */

public class JDBCUtils2 {

     private static final ComboPooledDataSource dataSourse=new ComboPooledDataSource();

/*

* 获得连接的方法:

* */

public static Connection getConnection() throws Exception{

Connection conn=dataSourse.getConnection();

return conn;

}

/**

* 资源释放

* */

public static void release(Statement stmt,Connection conn){

if(stmt!=null){

try {

stmt.close();

} catch (SQLException e) {

e.printStackTrace();

}

stmt=null;

}

if(conn!=null){

try {

conn.close();

} catch (SQLException e) {

e.printStackTrace();

}

conn=null;

}

 

}

public static void release(ResultSet rs, Statement stmt,Connection conn){

if(stmt!=null){

try {

stmt.close();

} catch (SQLException e) {

e.printStackTrace();

}

stmt=null;

}

if(conn!=null){

try {

conn.close();

} catch (SQLException e) {

e.printStackTrace();

}

conn=null;

}

if(rs!=null){

try {

rs.close();

} catch (SQLException e) {

e.printStackTrace();

}

rs=null;

}

}


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
提问者 德里克rose 2019-10-14 16:09:22

请问老师 是什么也问题报错

  • 同学你好,这个报错可能是因为项目中导入的MySQL的jar包版本和安装的MySQL版本不同造成的,建议同学检查项目中的jar版本和安装的MySQL的版本是否相同。祝:学习愉快~
    2019-10-14 16:56:48
好帮手慕阿满 2019-10-14 16:06:12

同学你好,问一下同学安装的MySQL是8的版本,项目中导入的MySQL的jar是否和安装的版本一直呢?建议同学检查一下,如果不一致,还请更换项目中MySQL的jar包版本。

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师