Public classdb{ Public StaticConnection Getconn () {Connection conn=NULL; Try{class.forname ("Com.mysql.jdbc.Driver"); Conn=Drivermanager.getconnection ("Jdbc:mysql://localhost:3306/bbs","Root","Root"); } Catch(Exception e) {e.printstacktrace (); } returnConn; } Public StaticStatement getstatement (Connection conn) {Statement stmt=NULL; Try{stmt=conn.createstatement (); } Catch(SQLException e) {e.printstacktrace (); } returnstmt; } Public StaticResultSet executeQuery (Statement stmt,string sql) {ResultSet rs=NULL; Try{RS=stmt.executequery (SQL); } Catch(SQLException e) {e.printstacktrace (); } returnrs; } Public Static voidClose (Connection conn) {if(Conn! =NULL) Try{conn.close (); } Catch(SQLException e) {e.printstacktrace (); } } Public Static voidClose (Statement stmt) {if(stmt! =NULL) Try{stmt.close (); } Catch(SQLException e) {e.printstacktrace (); } } Public Static voidClose (ResultSet rs) {if(rs! =NULL) Try{rs.close (); } Catch(SQLException e) {e.printstacktrace (); } }}
The package of DB