When encountering such a problem recently, it will be reported at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1905)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2351)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2862)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2988)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2917)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:824)
at com.zycy.db.DbTrans.executeQuery(DbTrans.java:127)
Such an error will be resolved after restarting the Tomcat service, but this problem will occur overnight.
The mysql JDBC URL format is as follows:
jdbc:mysql://[host:port],[host:port].../[database][?Parameter name 1][=Parameter value 1][&Parameter name 2][=Parameter value 2].. .
Several commonly used more important parameters:
Parameter name Parameter description Default value Minimum version requirement
user database username (used to connect to the database) all versions
password User password (used to connect to the database) All versions
useUnicode Whether to use the Unicode character set, if the parameter characterEncoding is set to gb2312 or gbk, this parameter value must be set to true false 1.1g
characterEncoding When useUnicode is set to true, specifies the character encoding. For example, it can be set to gb2312 or gbk false 1.1g
autoReconnect When the database connection is interrupted abnormally, is it automatically reconnected? false 1.1
autoReconnectForPools Whether to use the reconnection strategy for the database connection pool false 3.1.3
failOverReadOnly After automatic reconnection is successful, is the connection set to read-only? true 3.0.12
When maxReconnects autoReconnect is set to true, the number of connection retries is 3 1.1
initialTimeout When autoReconnect is set to true, the time interval between two reconnections, unit: seconds 2 1.1
connectTimeout The timeout when establishing a socket connection with the database server, unit: milliseconds. 0 means never timeout, applicable to JDK 1.4 and above 0 3.0.1
socketTimeout socket operation (read and write) timeout, unit: milliseconds. 0 means never timeout 0 3.0.1
Corresponding to the Chinese environment, usually the mysql connection URL can be set to:
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
When using a database connection pool, it is best to set the following two parameters:
autoReconnect=true&failOverReadOnly=false
It should be noted that in the xml configuration file, the & symbol in the url needs to be escaped into &. For example, when configuring the database connection pool in tomcat's server.xml, the mysql jdbc url sample is as follows:
jdbc:mysql://localhost:3306/test?user=root&password=&useUnicode=true&characterEncoding=utf8&autoReconnect