packagecn.bruce.MySql;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;public classConutils {//创建数据库连接的工具类
private static Connection con=null;static{
String usename= "root";
String password= "jinqi1986";
String url= "jdbc:mysql://localhost:3306/mytrain?useSSL=false&serverTimezone=CTT";
String jdbc= "com.mysql.cj.jdbc.Driver";try{
Class.forName(jdbc);
con=DriverManager.getConnection(url, usename, password);
}catch(Exception e)
{throw new RuntimeException(e + "数据库连接失败!");
}
}public staticConnection recon() {returncon;
}//创建数据库关闭的工具类(查询)
public static voidclose(Connection con,Statement st,ResultSet rs){if (rs!=null)
{try{
rs.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}if (st!=null)
{try{
st.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}if (con!=null)
{try{
con.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}
}//创建数据库关闭的工具类(非查询)
public static voidclose(Connection con,Statement st){if (st!=null)
{try{
st.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}if (con!=null)
{try{
con.close();
}catch(SQLException e)
{
e.printStackTrace();
}
}
}
}