import java.sql.*;
public class DB {
static {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private static Connection getConn() {
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydata?user=root&password=root");
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
private static Statement getStmt(Connection conn) {
Statement stmt = null;
try {
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
return stmt;
}
private static PreparedStatement getPStmt(Connection conn, String sql) {
PreparedStatement pStmt =null;
try {
pStmt = conn.prepareStatement(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return pStmt;
}
private static ResultSet executeQuery(Statement stmt, String sql) {
ResultSet rs = null;
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
private void closeConn(Connection conn) {
if(conn!=null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
conn = null;
}
}
private void closeStmt(Statement stmt) {
if(stmt!=null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
stmt = null;
}
}
private void closePStmt(Statement pStmt) {
if(pStmt !=null) {
try {
pStmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
pStmt = null;
}
}
private void closeRs(ResultSet rs) {
if(rs !=null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
rs = null;
}
}
}