首页 > 数据库技术 > 详细

SQLException: Communications link failure

时间:2016-03-04 22:45:57      阅读:497      评论:0      收藏:0      [点我收藏+]

连接数据库时出现如下错误提示:

SQLException: Communications link failure

 

The last packet sent successfully to the serverwas 0 milliseconds ago. The driver has not received any packets from theserver.

 

附上部分代码段:

publicstaticConnection getConnection() throws SQLException,

 java.lang.ClassNotFoundException

 {

   //第一步:加载MySQL的JDBC的驱动

   Class.forName("com.mysql.jdbc.Driver");

 

   //取得连接的url,能访问MySQL数据库的用户名,密码;jsj:数据库名

   String url = "jdbc:sqlserver://localhost:1433;DatabaseName=VisitSql";

   String username = "sa";

   String password = "123";

 

   //第二步:创建与MySQL数据库的连接类的实例

   Connection con = DriverManager.getConnection(url, username,password);

   returncon;

 }

 

原因分析:

本机Win7系统安装的是SQL Server 2008url设置为:

String url = "jdbc:sqlserver://localhost:1433;DatabaseName=VisitSql";

而初始是以MySQL的URL方式设置的:

 Stringurl = "jdbc:mysql://localhost:3306/VisitSql";

故而会出现上述错误。


本文出自 “DOSOM” 博客,谢绝转载!

SQLException: Communications link failure

原文:http://8656934.blog.51cto.com/8646934/1747714

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!