//工具类
publicclass JDBCUtil {
static String url = "jdbc:mysql://127.0.0.1:3306/sjt2405";//路径
static String user = "root";//数据库账号
static String password = "ROOT";//数据库密码
static{
//加载驱动
try{
Class.forName("com.mysql.cj.jdbc.Driver");
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
//获取连接
publicstatic Connection getConnection(){
Connection conn=null;
try{
conn= DriverManager.getConnection(url,user,password);
}catch(SQLException e){
e.printStackTrace();
}
return conn;
}
publicstaticvoidclose(Connection conn, PreparedStatement ps, ResultSet rs){
try{
if(conn!=null){
conn.close();
}
if(ps!=null){
ps.close();
}
if(rs!=null){
rs.close();
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
12-08
3万+
12-12
7703
04-20
1万+
09-07
8971
12-20
3444
07-10
1546
07-12
518
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交