标签:util driver getc public guide except stat private print
参考:https://www.runoob.com/w3cnote/jdbc-use-guide.html
即jdbc工具类,用于提供Connection对象
public class DbUtil {
public static final String URL = "jdbc:mysql://localhost:3306/imooc";
public static final String USER = "liulx";
public static final String PASSWORD = "123456";
private static Connection conn = null;
static{
try {
//1.加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
//2. 获得数据库连接
conn = DriverManager.getConnection(URL, USER, PASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static Connection getConnection(){
return conn;
}
}
void add(User user)throws SQLException{
Connection conn = DbUtils.getConnection();
//...
}
标签:util driver getc public guide except stat private print
原文地址:https://www.cnblogs.com/heibaimao123/p/13800495.html