//工具类
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();
}
}
}