[JDBC] 解决com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
2018-01-17 15:31
393 查看
原代码
然后出现了如下问题
纠结了一会 重启mysql 没有解决
然后修改为之前用的代码
就成功了
import java.sql.*; public class ex { public static void main(String[] argv){ Connection con; try{ Class.forName("com.mysql.jdbc.Driver"); }catch(Exception e){} String uri = "jdbc:mysql://192.168.100.1:3306/example?useSSL=true"; String user = "host"; String password = "******"; try{ con = DriverManager.getConnection(uri,user,password); Statement sql = con.createStatement(); ResultSet rs = sql.executeQuery("select * from student"); while(rs.next()){ String name = rs.getString(1); String sex = rs.getString(2); int id = rs.getInt(3); System.out.println(name+" "+sex+" "+id); } con.close(); }catch(SQLException e){ System.out.println(e); } } }
然后出现了如下问题
纠结了一会 重启mysql 没有解决
然后修改为之前用的代码
import java.sql.*; public class ex { public static void main(String[] argv){ Connection con; try{ Class.forName("com.mysql.jdbc.Driver"); }catch(Exception e){} /********/ String uri = "jdbc:mysql://localhost:3306/example?useSSL=true"; /********/ String user = "host"; String password = "******"; try{ con = DriverManager.getConnection(uri,user,password); Statement sql = con.createStatement(); ResultSet rs = sql.executeQuery("select * from student"); while(rs.next()){ String name = rs.getString(1); String sex = rs.getString(2); int id = rs.getInt(3); System.out.println(name+" "+sex+" "+id); } con.close(); }catch(SQLException e){ System.out.println(e); } } }
就成功了
相关文章推荐
- Cause: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying...的解决
- com.mysql.jdbc.CommunicationsException: Communications link failure之解决办法
- Cause: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying...的解决
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决办法
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决办法
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:的解决
- 解决mysql连接异常—-com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception
- 解决mysql连接异常—-com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception
- 如何解决com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:的解决
- JDBC学习之道:JDBC中的Communications link failure due to underlying exception错误的解决办法
- 解决MySQL连接超时Communications link failure due to underlying exception
- Communications link failure的解决办法
- 解决MySQL连接超时Communications link failure due to underlying exception
- MyBatis数据库连接出现Communications link failure现象的解决办法(dbcp2连接池)
- Communications link failure异常解决
- 解决MySQL连接超时Communications link failure due to underlying exception
- mysql 5.1超过默认8小时空闲时间解决办法(错误:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure)
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- 【错误】:Could not open JDBC Connection for transaction; nested exception is: Communications link failure;The last packet sent successfully to the server was 1 milliseconds ago