Ejemplo n.º 1
0
 public int getRsCountForSQL(String sql) {
   Connection conn = null;
   Statement stmt = null;
   ResultSet rs = null;
   try {
     conn = SqlServerConn.getConn();
     stmt = conn.createStatement();
     rs = stmt.executeQuery(sql);
     if (rs.next()) {
       this.rscount = rs.getInt("num"); // num为SQL语句中指定,select count(id) num from.....
     } else {
       this.rscount = 0;
     }
   } catch (Exception ex) {
     ex.printStackTrace();
     this.rscount = 0;
   } finally {
     SqlServerConn.ConnClose(conn, stmt, rs);
   }
   return this.rscount;
 }
Ejemplo n.º 2
0
  /** 传入SQL语句获取总记录数 */
  public int getRsCountForRs(String sql) {
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
      conn = SqlServerConn.getConn();
      stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      rs = stmt.executeQuery(sql);
      if (rs.next()) {
        rs.last();
        this.rscount = rs.getRow();
      } else {
        this.rscount = 0;
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      this.rscount = 0;
    } finally {
      SqlServerConn.ConnClose(conn, stmt, rs);
    }
    return this.rscount;
  }