package ehomework;
import java.sql.*;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */public class ConnDb {  public String _user;
   public String _durl;
   public String _driver;
   public String _pass;
   Statement _stmt;
   Connection _conn=null;   public ConnDb() {
     _user="sa";
     _pass="sa";
     _driver="sun.jdbc.odbc.JdbcOdbcDriver";
     _durl="jdbc:odbc:test";
   }   public ConnDb(String username,String password,String durl,String driver){
     _user=username;
     _pass=password;
     _durl=durl;
     _driver=driver;
   }   public Connection myConn(){
     try{
       Class.forName(_driver);
       _conn=DriverManager.getConnection(_durl,_user,_pass);
     }catch(Exception e){
       System.err.println("connDB's myConn() throw exception:"+e.getMessage());
     }
     return _conn;
   }   public ResultSet execQuery(String sqlstr){
     ResultSet rs=null;
     try{
       Connection rsConn=myConn();
       _stmt=rsConn.createStatement();
       rs=_stmt.executeQuery(sqlstr);
       System.out.println("The SQL Statement is:"+sqlstr);
     }catch(SQLException ex){
       System.err.println("connDB's execQuery() throw sqlexception:"+ex.getMessage());
       System.err.println("The SQL Statement is:"+sqlstr);
     }
     return rs;
   }   public void execUpdate(String sqlstr){
     try{
       Connection upConn=myConn();
       _stmt=upConn.createStatement();
       _stmt.executeUpdate(sqlstr);
      System.out.println("The SQL Statement is:"+sqlstr);
     }catch(SQLException ex){
       System.err.println("connDB's execUpdate() throw sqlException:"+ex.getMessage());
       System.err.println("The SQL Statement is:"+sqlstr);
     }
   }   public void myClose(){
     try{
       _stmt.close();
       _conn.close();
     }catch(SQLException ex){
       System.err.println("connDB's myClose() throw SQLException:"+ex.getMessage());
     }
   }
}