当前位置: 首页 > Java > 正文

CommunicationsException Communications link failure

关键字:
1 星2 星3 星4 星5 星 (2 次投票, 评分: 5.00, 总分: 5)
Loading ... Loading ...
baidu_share

通过JDBC连接MySQL出现com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link failure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure  
 
The last packet successfully received from the server was 276 milliseconds ago.  The last packet sent successfully to the server was 50 milliseconds ago.  
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)  
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)  
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)  
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)  
        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)  
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3591)  
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3480)  
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4021)  
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)  
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)  
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2671)  
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2621)  
        at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1557)  
        at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3892)  
        at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3437)  
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2437)  
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2207)  
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:797)  
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)  
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)  
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)  
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)  
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)  
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)  
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)  
        at java.sql.DriverManager.getConnection(DriverManager.java:582)  
        at java.sql.DriverManager.getConnection(DriverManager.java:185)  
        at TestJDBC.getConnection(TestJDBC.java:19)  
        at TestJDBC.testResult(TestJDBC.java:76)  
        at TestJDBC.main(TestJDBC.java:13)  
Caused by: java.io.EOFException: Can not read response from s

经检查由于设置了屏幕保护程序,导致mysql配置的testConnection测试程序未联通。mysql和程序都在本机。

1
2
3
4
5
6
7
8
9
10
          <property name="minPoolSize"><value>1</value></property>
          <property name="maxPoolSize"><value>10</value></property>
          <property name="maxIdleTime"><value>6000</value></property>
          <property name="acquireIncrement"><value>1</value></property>
          <property name="maxStatements"><value>0</value></property>
          <property name="initialPoolSize"><value>3</value></property>
          <property name="idleConnectionTestPeriod"><value>6000</value></property>
          <property name="acquireRetryAttempts"><value>10</value></property>
          <property name="breakAfterAcquireFailure"><value>true</value></property>
          <property name="testConnectionOnCheckout"><value>false</value></property>

在c3p0配置文件中加入:

1
<property name="preferredTestQuery"><value>SELECT 1</value></property>

问题解决。

本文固定链接: http://www.chepoo.com/com-mysql-jdbc-exceptions-jdbc4-communications-exception.html | IT技术精华网

CommunicationsException Communications link failure:等您坐沙发呢!

发表评论