mysql数据库连接问题
ResultSetrs=null;Statementstmt=null;Connectionconn=null;Class.forName("com.mysql.jdbc...
ResultSet rs = null;
Statement stmt = null;
Connection conn =null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url ="jdbc:mysql://localhost/mybbs";
conn = DriverManager.getConnection(url,"root","root");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from posts");
为什么在conn = DriverManager.getConnection(url,"root","root");这句报错
javax.servlet.ServletException: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect 展开
Statement stmt = null;
Connection conn =null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url ="jdbc:mysql://localhost/mybbs";
conn = DriverManager.getConnection(url,"root","root");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from posts");
为什么在conn = DriverManager.getConnection(url,"root","root");这句报错
javax.servlet.ServletException: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect 展开
1个回答
展开全部
如果报错的话把错误贴出来,还有就是你倒没倒连接jar包,3个jar加在程序里了吗?
import java.sql.*;
Connection conn =null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost/mybbs", "root", "root");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
import java.sql.*;
Connection conn =null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost/mybbs", "root", "root");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询