Package com.shopping.util;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.sql.Statement;
public class DB {
static {
try {
Class.forName ("Com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
E.printstacktrace ();
}
}
Public DB () {
}
public static Connection Getconn () {
Connection conn = null;
try {
conn = Drivermanager.getconnection ("Jdbc:mysql://localhost:3306/bbs?user=root");
} catch (SQLException e) {
E.printstacktrace ();
}
Return conn;
}
public static Statement getstmt (Connection conn) {
Statement stmt = null;
try {
stmt = Conn.createstatement ();
} catch (SQLException e) {
E.printstacktrace ();
}
return stmt;
}
public static PreparedStatement getprepstmt (Connection conn,string sql) {
PreparedStatement pstmt = null;
try {
pstmt = conn.preparestatement (sql);
} catch (SQLException e) {
E.printstacktrace ();
}
return pstmt;
}
public static ResultSet getrset (Statement stmt,string sql) {
ResultSet rs = null;
try {
rs = stmt.executequery (SQL);
} catch (SQLException e) {
E.printstacktrace ();
}
Return RS;
}
public static ResultSet Getpreprset (PreparedStatement pstmt) {
ResultSet rs = null;
try {
rs = Pstmt.executequery ();
} catch (SQLException e) {
E.printstacktrace ();
}
Return RS;
}
public static void Close (Connection conn) {
IF (conn! = null) {
try {
Conn.close ();
} catch (SQLException e) {
E.printstacktrace ();
}
conn = null;
}
}
public static void Close (PreparedStatement pstmt) {
if (pstmt! = null) {
try {
Pstmt.close ();
} catch (SQLException e) {
E.printstacktrace ();
}
pstmt = null;
}
}
public static void Close (ResultSet rs) {
if (rs! = null) {
try {
Rs.close ();
} catch (SQLException e) {
E.printstacktrace ();
}
rs = null;
}
}
}