www.pudn.com > Cert.rar > DBConn.java


import java.sql.Blob; 
import java.sql.Clob; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.NClob; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.sql.SQLXML; 
import java.sql.Statement; 
 
 
public class DBConn { 
 
    Connection conn;  
    public DBConn() throws SQLException { 
    	String userName = "root";  
    	String userPwd = "123456"; 
    	conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Cert_DB", userName, userPwd); 
    	} 
 
    public ResultSet getResult(String query) throws SQLException { 
        Statement stm = conn.createStatement(); 
        return stm.executeQuery(query); 
    } 
 
    public int execute(String query) throws SQLException { 
        Statement stm = conn.createStatement(); 
        return stm.executeUpdate(query); 
    } 
 
    public Statement createStatement() throws SQLException { 
        return conn.createStatement(); 
    } 
 
    public PreparedStatement prepareStatement(String sql) throws SQLException { 
        return conn.prepareStatement(sql); 
    } 
 
     
    public void close() throws SQLException { 
        conn.close(); 
    } 
 
    public void setReadOnly(boolean readOnly) throws SQLException { 
        conn.setReadOnly(readOnly); 
    } 
 
    public void rollback() throws SQLException { 
        conn.rollback(); 
    } 
 
    public boolean isValid(int timeout) throws SQLException { 
        return conn.isValid(timeout); 
    } 
 
    public boolean isReadOnly() throws SQLException { 
        return conn.isReadOnly(); 
    } 
 
    public boolean isClosed() throws SQLException { 
        return conn.isClosed(); 
    } 
 
    public SQLXML createSQLXML() throws SQLException { 
        return conn.createSQLXML(); 
    } 
 
    public NClob createNClob() throws SQLException { 
        return conn.createNClob(); 
    } 
 
    public Clob createClob() throws SQLException { 
        return conn.createClob(); 
    } 
 
    public Blob createBlob() throws SQLException { 
        return conn.createBlob(); 
    } 
 
    public void commit() throws SQLException { 
        conn.commit(); 
    } 
     
     
 
    static { 
        try { 
            Class.forName("org.gjt.mm.mysql.Driver"); 
        } catch (ClassNotFoundException classNotFoundException) { 
            throw new ExceptionInInitializerError(classNotFoundException); 
        } 
    } 
}