JAVA纯驱动连接MYSQL数据库出现服务器内部错误

Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager
.getConnection("jdbc:mysql://localhost:8080/company?uer=root&password=root");
String sql = "select * from emp";
ResultSet rs = conn.createStatement().executeQuery(sql);
这是连接代码,不知道哪里出现问题。
javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
description The server encountered an internal error that prevented it from fulfilling this request.
这是错误代码

这个是连接错误
("jdbc:mysql://localhost:8080/company?uer=root&password=root"); //uer应为user

去掉8080,看看你的mysql端口号是不是3306,如果是就用下面的
("jdbc:mysql://localhost/company?user=root&password=root");
或者
("jdbc:mysql://localhost:3306/company?user=root&password=root");

如果不是就改为其他端口号
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-29
端口号错啦,8080应该是tomcat的端口号,mysql的端口号是3306
第2个回答  2013-09-29
mysql默认端口号是3306,要是别的你需要自己查看一下,

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网