用myeclipse6连接mysql数据库时出现communication link failure due to underlyin
2个回答
展开全部
import java.sql.*;
import javax.sql.*;
public class QQJDBCConnector {
Connection conn;
String url;
String user;
String pws;
public QQJDBCConnector() {
url="jdbc:mysql://localhost/数据库名?useUnicode=true&characterEncoding=utf-8";
user="用户名";
pws="用户密码";
conn=null;
}
public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection(url,user,pws);
}
catch (Exception e) {
System.out.println("Error occurred obtaining connection");
System.out.println(e.getMessage());
}
return conn;
}
}
import javax.sql.*;
public class QQJDBCConnector {
Connection conn;
String url;
String user;
String pws;
public QQJDBCConnector() {
url="jdbc:mysql://localhost/数据库名?useUnicode=true&characterEncoding=utf-8";
user="用户名";
pws="用户密码";
conn=null;
}
public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection(url,user,pws);
}
catch (Exception e) {
System.out.println("Error occurred obtaining connection");
System.out.println(e.getMessage());
}
return conn;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public static Connection getvpop() {
String sDBDriver = "com.mysql.jdbc.Driver";
String db = "数据库名称";
// String user = "sales";
String user = "root";
String passwd = "111111";
String sConnStr = "jdbc:mysql://localhost:3306/" + db + "?user="
+ user + "&password=" + passwd
+ "&useUnicode=true&characterEncoding=utf-8";
// String sConnStr = "jdbc:mysql://210.74.155.106:3306/" + db + "?user="
// + user + "&password=" + passwd
// + "&useUnicode=true&characterEncoding=utf-8";
Connection conn = null;
try {
Class.forName(sDBDriver);
conn = DriverManager.getConnection(sConnStr);
} catch (ClassNotFoundException e) {
System.err.println("数据库连接失败:***************&&&&&&&&&&&&"
+ e.getMessage());
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
String sDBDriver = "com.mysql.jdbc.Driver";
String db = "数据库名称";
// String user = "sales";
String user = "root";
String passwd = "111111";
String sConnStr = "jdbc:mysql://localhost:3306/" + db + "?user="
+ user + "&password=" + passwd
+ "&useUnicode=true&characterEncoding=utf-8";
// String sConnStr = "jdbc:mysql://210.74.155.106:3306/" + db + "?user="
// + user + "&password=" + passwd
// + "&useUnicode=true&characterEncoding=utf-8";
Connection conn = null;
try {
Class.forName(sDBDriver);
conn = DriverManager.getConnection(sConnStr);
} catch (ClassNotFoundException e) {
System.err.println("数据库连接失败:***************&&&&&&&&&&&&"
+ e.getMessage());
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询