import java.sql.Connection;
import java.sql.DriverManager;
public class DatabaseConn {
private static Connection conn;
private String url = "jdbc:mysql://:localhost:3306/user";
private String username = "root";
private String password = "123456";
private String className = "com.mysql.jdbc.Driver"; //数据库驱动类
public Connection getConnection() {
try {
Class.forName(className).newInstance(); //加载数据库驱动
//获得数据库连接对象
conn = DriverManager.getConnection(url, username, password);
System.out.println("SUCCESS");
} catch (Exception e) {
e.printStackTrace();
System.out.println("ERROR");
}
return conn;
}
}