package Data;
import java.sql.*;
public class database{
private Connection conn=null;
ResultSet rs=null;
private Statement stmt=null;
PreparedStatement pstmt=null;
public database(){}
public void OpenConn(String dsn,String uid,String pwd) throws Exception{
try{
dsn="jdbc:odbc:"+dsn;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection(dsn,uid,pwd);
}catch(Exception ex)
{System.err.println("aq.executeQuery:"+ex.getMessage());}
}
public ResultSet executeQuery(String sql){
try{
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql);
}catch(SQLException ex){System.err.println(ex.getMessage());}
return rs;
}
public PreparedStatement executeUpdate(String sql){
try{
pstmt=conn.prepareStatement(sql);
pstmt.executeUpdate();
}catch(SQLException ex){System.err.println(ex.getMessage());}
return pstmt;
}
public void closePstmt(){
try{pstmt.close();}
catch(SQLException ex){System.err.println(ex.getMessage());}
}
public void closeStmt(){
try{stmt.close();}
catch(SQLException ex){System.err.println(ex.getMessage());}
}
public void closeConn(){
try{conn.close();}
catch(SQLException ex){System.err.println("aq.executeQuery:"+ex.getMessage());}
}
}
感觉有冗余代码!或者在多次查询和多次更新的时候会出现错误?
请教了!