打印本文 打印本文 关闭窗口 关闭窗口
用javabean来实现MySQL的分页显示
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1650  更新时间:2009/4/22 20:44:53  文章录入:mintao  责任编辑:mintao
;    catch (SQLException e)
      {
          System.out.print("SQL Exception occur. Message is:");
          System.out.print(e.getMessage());     
      }    
  }   
   
    
  // perform a query with records returned
  public ResultSet executeQuery(String sql)  throws SQLException
  {     
      
      ResultSet rs = null;        
      try
      {
          stmt = con.createStatement();
          rs = stmt.executeQuery(sql);    
          while(rs.next())
              this.rows ++;         
          rs = stmt.executeQuery(sql);
      }
      catch (SQLException e)
      {
          System.out.print("Query:"+e.getMessage());
      }    
      
      this.rs = rs;
      return rs;    
  }

  // perform a query without records returned
  public boolean executeUpdate(String sql)  
  {     
      try
      {
          stmt = con.createStatement();
          stmt.executeUpdate(sql);                            
          return true;    
      }
      catch(SQLException e)
      {
          System.out.print("Update:"+e.getMessage());
          return false;
      }
  }

  // return the num of columns    
  public int getColumns()
  {
     int columns = 0;
     try
     {
          this.resultsMeta = this.rs.getMetaData();
          columns = this.resultsMeta.getColumnCount();
     }
     catch (SQLException e)  {}
     return columns;
  }

  // return the num of rows
  public int getRows()
  {
     return this.rows;
  }

  public String getDBName() {
      return this.dbName;
  }

}

上一页  [1] [2] 

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