Package util;
Import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. PreparedStatement;
Import java. SQL. ResultSet;
Public class DBUtil {
Connection conn = null;
PreparedStatement stmt = null;
String Driver = "com. mysql. jdbc. Driver ";
String url = "jdbc: mysql: // 10.137.5.23/mcip? UseUnicode = true & characterEncoding = GBK ";
String user = "mcip ";
String password = "mcip ";
ResultSet rs = null;
// Complete the connection Creation
Public Connection getConnection () throws Exception {
Class. forName (Driver );
If (conn = null ){
Conn = DriverManager. getConnection (url, user, password );
}
Return conn;
}
// Create a statement object
Public PreparedStatement createStatement (String SQL) throws Exception {
Stmt = getConnection (). prepareStatement (SQL );
Return stmt;
}
// Execute the method returned by the result set
Public ResultSet excuteQuery () throws Exception {
Rs = stmt.exe cuteQuery ();
Return rs;
}
// Execute the method without returning the result set
Public int excuteUpdate () throws Exception {
Return stmt.exe cuteUpdate ();
}
// Close the object
Public void close (){
If (rs! = Null) try {rs. close ();} catch (Exception e ){}
If (stmt! = Null) try {stmt. close ();} catch (Exception e ){}
If (conn! = Null) try {conn. close ();} catch (Exception e ){}
}
}