打印本文 打印本文 关闭窗口 关闭窗口
Linux 网络服务器构架实务之七
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2450  更新时间:2009/4/22 20:46:07  文章录入:mintao  责任编辑:mintao
   }

// ------------------------------------------------------------------------------------

 

//连接数据库的方法

    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]  下一页

打印本文 打印本文 关闭窗口 关闭窗口