发布时间:2023-03-25 18:00
public static Connection conn = null;
private static final String driver ="com.mysql.cj.jdbc.Driver";
private static final String url = "jdbc:mysql://localhost:3306/statusdata?useSSL=false";
private static final String user = "root";
private static final String pwd = "123lgk";
//建立连接
public static void ConnectJdbc()
{
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, user, pwd);
}catch (Exception ex)
{
System.out.println("错误信息:" + ex.getMessage());
}
}
//变量全肯定的增删改
public static Statement getStatement()throws Exception
{
ConnectJdbc();
return conn.createStatement();
}
//变量未知但后赋值的增删改
public static PreparedStatement getPreStatement(String sql)throws Exception
{
ConnectJdbc();
return conn.prepareStatement(sql);
}
//变量全肯定的查询
public static ResultSet getSta_ResultSet(String sql) throws Exception
{
return getStatement().executeQuery(sql);
}
//变量未知但后赋值的查询
public static ResultSet getPre_ReResultSet(PreparedStatement ps) throws Exception
{
return ps.executeQuery();
}