在几秒钟之后,我们收到一个CommunicationsException(来自DBCP).错误消息(在异常中)是在此问题的结尾 – 但我没有看到任何配置文件中定义的wait_timeout. (我们应该在哪里看?tomcat / conf目录中的某个地方?).
其次,正如Exception所建议的那样,将“Connector / J connection属性”autoReconnect = true’“放在哪里?这是Tomcat中文件conf / context.xml中的资源定义设置:
maxActive="100" maxIdle="30" maxWait="10000"
removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"
username="xxxx" password="yyyy"
driverClassName="com.MysqL.jdbc.Driver"
url="jdbc:MysqL://127.0.0.1:3306/dbname?autoReconnect=true"/>
第三,为什么JVM等待调用executeQuery()来抛出异常?如果连接超时,getConnection方法应该抛出异常,不应该吗?这是我在谈论的源代码部分:
try {
conn = getConnection (true);
stmt = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rset = stmt.executeQuery (bQuery);
while (rset.next()) {
....
最后,这里是堆栈跟踪的第一行
com.MysqL.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 84,160,724 milliseconds ago. The last packet sent successfully to the server was 84,848 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application,increasing the server configured values for client timeouts,or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.MysqL.jdbc.Util.handleNewInstance(Util.java:406)
at com.MysqL.jdbc.sqlError.createCommunicationsException(sqlError.java:1074)
at com.MysqL.jdbc.MysqLIO.send(MysqLIO.java:3291)
at com.MysqL.jdbc.MysqLIO.sendCommand(MysqLIO.java:1938)
at com.MysqL.jdbc.MysqLIO.sqlQueryDirect(MysqLIO.java:2107)
at com.MysqL.jdbc.ConnectionImpl.execsql(ConnectionImpl.java:2642)
at com.MysqL.jdbc.ConnectionImpl.execsql(ConnectionImpl.java:2571)
at com.MysqL.jdbc.StatementImpl.executeQuery(StatementImpl.java:1451)
at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
这些是我们一些人认为“忘记dbcp”的原因,它可能依赖于IDE配置和引擎下的魔术,DriverManager.getConnection(…)可能更可靠“.有什么意见吗?谢谢你的见解 – MS