您当前的位置: 首页 > 

txwtech

暂无认证

  • 1浏览

    0关注

    813博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

The last packet sent successfully to the server was 0 milliseconds ago. The driver 解决方法

txwtech 发布时间:2018-06-24 22:58:27 ,浏览量:1

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
主要查看url写正确没有。
比如:url="jcbc:mysql://localhost3306/db_cjky"; 在3306少了一个冒号。服务器无法链接,就报此错误。

public class StudentDao {
	
	public Connection getConnection() {
		Connection conn=null;
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			String url="jdbc:mysql://localhost:3306/db_cjky";
			String username="root";
			String password="123456";
			conn=DriverManager.getConnection(url, username, password);
		}catch(ClassNotFoundException e) {
			e.printStackTrace();
		}catch(SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
关注
打赏
1665060526
查看更多评论
立即登录/注册

微信扫码登录

0.0415s