昨天还运行好好的,今天运行出错!怪哉怪哉!
错误信息如下:
- com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Server connection failure during
- transaction. Due to underlying exception: 'com.mysql.jdbc.CommunicationsException: Communications link
- failure due to underlying exception:
- ** BEGIN NESTED EXCEPTION **
- java.net.SocketException
- MESSAGE: Connection reset
- STACKTRACE:
- java.net.SocketException: Connection reset
- at java.net.SocketInputStream.read(SocketInputStream.java:168)
- at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
- at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary
- (ReadAheadInputStream.java:160)
- at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
- at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1910)
- at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
- at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
- at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
- at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
- at com.mysql.jdbc.Connection.execSQL(Connection.java:3170)
- at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5273)
- at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4066)
- at com.mysql.jdbc.Connection.createNewIO(Connection.java:2833)
- at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
- at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
- at java.sql.DriverManager.getConnection(DriverManager.java:525)
- at java.sql.DriverManager.getConnection(DriverManager.java:171)
- at com.database.HangdianJDBC.<init>(HangdianJDBC.java:24)
- at com.core.ProcessHangdian.initialize(ProcessHangdian.java:34)
- at com.core.ProcessHangdian.main(ProcessHangdian.java:161)
- ** END NESTED EXCEPTION **
- Last packet sent to the server was 94 ms ago.'.
- ** BEGIN NESTED EXCEPTION **
- com.mysql.jdbc.CommunicationsException
- MESSAGE: Communications link failure due to underlying exception:
- ** BEGIN NESTED EXCEPTION **
- java.net.SocketException
- MESSAGE: Connection reset
- STACKTRACE:
- java.net.SocketException: Connection reset
- at java.net.SocketInputStream.read(SocketInputStream.java:168)
- at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
- at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary
- (ReadAheadInputStream.java:160)
- at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
- at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1910)
- at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
- at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
- at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
- at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
- at com.mysql.jdbc.Connection.execSQL(Connection.java:3170)
- at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5273)
- at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4066)
- at com.mysql.jdbc.Connection.createNewIO(Connection.java:2833)
- at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
- at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
- at java.sql.DriverManager.getConnection(DriverManager.java:525)
- at java.sql.DriverManager.getConnection(DriverManager.java:171)
- at com.database.HangdianJDBC.<init>(HangdianJDBC.java:24)
- at com.core.ProcessHangdian.initialize(ProcessHangdian.java:34)
- at com.core.ProcessHangdian.main(ProcessHangdian.java:161)
- ** END NESTED EXCEPTION **
- Last packet sent to the server was 94 ms ago.
- STACKTRACE:
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- ** BEGIN NESTED EXCEPTION **
- java.net.SocketException
- MESSAGE: Connection reset
- STACKTRACE:
- java.net.SocketException: Connection reset
- at java.net.SocketInputStream.read(SocketInputStream.java:168)
- at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
- at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary
- (ReadAheadInputStream.java:160)
- at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
- at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1910)
- at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
- at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
- at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
- at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
- at com.mysql.jdbc.Connection.execSQL(Connection.java:3170)
- at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5273)
- at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4066)
- at com.mysql.jdbc.Connection.createNewIO(Connection.java:2833)
- at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
- at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
- at java.sql.DriverManager.getConnection(DriverManager.java:525)
- at java.sql.DriverManager.getConnection(DriverManager.java:171)
- at com.database.HangdianJDBC.<init>(HangdianJDBC.java:24)
- at com.core.ProcessHangdian.initialize(ProcessHangdian.java:34)
- at com.core.ProcessHangdian.main(ProcessHangdian.java:161)
- ** END NESTED EXCEPTION **
- Last packet sent to the server was 94 ms ago.
- at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2515)
- at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
- at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
- at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
- at com.mysql.jdbc.Connection.execSQL(Connection.java:3170)
- at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5273)
- at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4066)
- at com.mysql.jdbc.Connection.createNewIO(Connection.java:2833)
- at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
- at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
- at java.sql.DriverManager.getConnection(DriverManager.java:525)
- at java.sql.DriverManager.getConnection(DriverManager.java:171)
- at com.database.HangdianJDBC.<init>(HangdianJDBC.java:24)
- at com.core.ProcessHangdian.initialize(ProcessHangdian.java:34)
- at com.core.ProcessHangdian.main(ProcessHangdian.java:161)
- ** END NESTED EXCEPTION **
大体上知道是连接失效的原因。
在JDBC的url中加入autoReconnect=true。
代码如下:
- jdbc.driverClassName=com.mysql.jdbc.Driver
- jdbc.url=jdbc:mysql://s43.eatj.com:3307/caoxu?autoReconnect=true&useUnicode=true&characterEncoding=utf8
- jdbc.username=caoxu
- jdbc.password=cao1987
可是还是很不稳定,一直出错,我就一直重试,烦死了!算了,不搞了!实在不行的话,就不通过phpMyadmin进行存储数据了,而且速度很慢。直接在本机上通过Mysql存储,然后进行转换为sql文件,导入到phpMyadmin中。这种做法唯一不好的就是导入时有大小限制……