数据库的执行类:
import java.sql.*;/**
 *
 * @author  user
 */
public class DBOperation {
    private String strDbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
    private String strConn = "jdbc:odbc:DBname";
    private Connection conn = null;
    private ResultSet result = null;
    private String strUser = "sa";
    private String strPassword = "";
    
    /**
     * constructor
     */
    public DBOperation() {
        try{
            Class.forName( strDbDriver );
        } catch( ClassNotFoundException ex ) {
            System.err.println( ex.getMessage() );
        }
    }
    
    /**
     * constructor
     * @param strUser      database user
     * @param strPassword  user password
     */
    public DBOperation(String strUser, String strPassword) {
        this();
        this.strUser = strUser;
        this.strPassword = strPassword;
    }
    
    
    /**
     * execute query and retrive the data
     * @param strSql  SQL string( select )
     * @return result data
     *
     * @throws SQLException
     */
    public ResultSet executeQuery( String strSql ) throws SQLException {
        // clear result set
        result = null;
        
        // get Connection
        conn = DriverManager.getConnection( strConn, strUser, strPassword );
        Statement st = conn.createStatement();
        
        // query
        return st.executeQuery( strSql );
    }
    
    /**
     * modify the data in database
     * @param strSql SQL string ( delete, insert and update )
     * @return execute result
     *         -1: error
     *         other: normal(the count of the data rows modified )
     *
     * @throws SQLException
     */
    public int executeUpdate( String strSql ) throws SQLException {
        // return value
        int nRetValue = -1;
        
        // get connection
        conn = DriverManager.getConnection( strConn, strUser, strPassword );
        Statement st = conn.createStatement();
        
        // update
        nRetValue = st.executeUpdate( strSql );
        
        // close Statement and Connection
        st.close();
        conn.close();
        
        return nRetValue;
    }
}