| }
// ------------------------------------------------------------------------------------
//连接数据库的方法
public void open()
throws SQLException {
if( conn!=null && !conn.isClosed() )
throw new SQLException( "The connection has been established already." ) ;
clear () ;
pool=new DBPool();
conn = pool.getPool("your_data_source_name").getConnection();
}
//执行SQL语句的方法,将JDBC中的executeQuary()和executeUpdate()两个方法//合而为一,注意返回值为整形,
public int execSQL( String sqlStmt )
throws SQLException {
if( conn==null || conn.isClosed() )
throw new SQLException( "This connection has not been established yet." ) ;
if( sqlStmt==null )
throw new SQLException( "SQL-statement is null." ) ;
clear () ;
conn.setAutoCommit( true ) ;
stmt=conn.createStatement() ;
if( sqlStmt.toUpperCase().startsWith( "SELECT" ) ) {
rs=stmt.executeQuery( sqlStmt ) ;
return -1 ;
}
else {
int numRow=stmt.executeUpdate( sqlStmt ) ;
clear() ;
return numRow ;
}
}
//获取字段值,参数为整形——字段次序
public String getString( int fieldNo )
throws SQLException {
return rs.getString(fieldNo) ;
}
//获取字段值,参数为字符串——字段名
public String getString( String fieldName )
throws SQLException {
return rs.getString(fieldName) ;
}
//上移指针
public boolean previous()
throws SQLException {
上一页 [1] [2] [3] [4] 下一页 |