如题所述
é¦å
导å
¥é©±å¨jarå
ï¼ç¨åºæ¯
package test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class connectionMySql {
private static Connection connection;
static{
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/purview";
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.print("å 载驱å¨å¤±è´¥");
e.printStackTrace();
}
try {
connection=DriverManager.getConnection(url, "root", "root");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConnection() {
return connection;
}
public static void main(String [] args) {
Connection con=connectionMySql.getConnection();
if(!con.equals("")){
System.out.print("æ°æ®åºè¿æ¥æåï¼è¿æ¥idæ¯:"+con);
}
}
}
package test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class connectionMySql {
private static Connection connection;
static{
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/purview";
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.print("å 载驱å¨å¤±è´¥");
e.printStackTrace();
}
try {
connection=DriverManager.getConnection(url, "root", "root");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConnection() {
return connection;
}
public static void main(String [] args) {
Connection con=connectionMySql.getConnection();
if(!con.equals("")){
System.out.print("æ°æ®åºè¿æ¥æåï¼è¿æ¥idæ¯:"+con);
}
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2020-04-19
我的B站:https://space.bilibili.com/410670572资料视频:https://baijiahao.baidu.com/u?app_id=1616309264508817QQ群:1097414647有任何问题,可以在B站或者百家号留言联系我。微信公众号:学习编程笔记