java 配置dbcp_java – 使用DBCP进行Tomcat配置

在几秒钟之后,我们收到一个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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值