资 源 简 介
public class DBConnection {
private Connection connection;
private String db_Name = "qian";
private String db_User = "root";
private String db_Password = "lubing";
public DBConnection(){
this.getConection();
}
/*
* 得到Connection对象。
*/
public Connection getConection(){
try {
// 加载数据库驱动
Class.forName("com.mysql.jdbc.Driver");
// 指定连接数据库的URL
String url = "jdbc:mysql://localhost:3306/" + db_Name;
// 通过DriverManager的getConnection()建立连接
connection = DriverManager.getConnection(url, db_User, db_Password);
if (connection == null) {
System.out.println("数据连接出错了!");
}
} catch (Exception e) {
e.printStackTrace();
}
return connection ;
}
/*
* 关闭数据集/语句/连接对象
*/
public void close(Resul