概述
我在 tomcat conf 目录下配置了一个jndi
<Resource
name="jdbc/mydb"
scope="Shareable"
type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
url="jdbc:mysql://localhost:3306/mydb"
driverClassName ="com.mysql.jdbc.Driver"
username="aaa"
password="123456"
/>
刚开始使用没问题,一段时间之后出现这个错误
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1956)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2368)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3255)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1428)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at com.blasetti.ordiniweb.dao.OrdiniDAO.caricaOrdine(OrdiniDAO.java:263)
...
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2579)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
com.mysql.jdbc.Connection.execSQL(Connection.java:3255)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1428)
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
com.blasetti.ordiniweb.dao.OrdiniDAO.caricaOrdine(OrdiniDAO.java:263)
...
这是因为服务端一段时间之后会假定客户端已经断开连接了,所以主动断开,而客户端不知道,所以再使用这个连接池的时候就会报这个错。解决办法是配置客户端连接池的定期检查
<Resource
name="jdbc/mydb"
scope="Shareable"
type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
url="jdbc:mysql://localhost:3306/mydb?autoReconnect=true&useUnicode=true&characterEncoding=utf8"
driverClassName ="com.mysql.jdbc.Driver"
username="abc"
password="123456"
validationQuery="Select 1"
maxActive="100"
maxIdle="30"
maxWait="10000"
/>
解释下
增加?autoReconnect=true&useUnicode=true&characterEncoding=utf8
增加validationQuery="Select 1"
---------------------
作者:alexxiyang
来源:CSDN
原文:https://blog.csdn.net/nsrainbow/article/details/39135265
版权声明:本文为博主原创文章,转载请附上博文链接!
最后
以上就是大力小霸王为你收集整理的tomcat jndi 连接 mysql 报 BEGIN NESTED EXCEPTION 错误的解决办法的全部内容,希望文章能够帮你解决tomcat jndi 连接 mysql 报 BEGIN NESTED EXCEPTION 错误的解决办法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复