Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 08 Jun 2007 @ 11:18:06 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: JDBC and the number of records being returned
 
From:   D silva, Joseph Vinish

  So...Does anyone know if there is a way using jdbc to capture the number of records being returned without having to return the entire recordset?  


  I know that in Queryman you can see the # of rows being returned and even if you cancel the return after 200 rows the answerset size shows how many were >>found with the sql. Any insight here would be help so I can point them the right way.  


This is one way, I know of, pay particular attention to the parameters passed to the createStatement request. You would get more information on the various function calls and parameters used from the Sun JDK Documentation on java.sql.ResultSet (available from Sun website)

     {

     // ..... stuff

     Connection conn = DriverManager.getConnection(jdbcUrl, userId,
     password);
     ResultSet rs = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
     ResultSet.CONCUR_READ_ONLY).executeQuery(query);

     System.out.println ("Row count for resultset is : " + getRowCount(rs));


     }

     static int getRowCount(ResultSet rs) throws SQLException
     {
       // This action is valid only for scrollable result sets
       if (rs == null || rs.getType() != ResultSet.TYPE_SCROLL_INSENSITIVE &&
     rs.getType() != ResultSet.TYPE_SCROLL_SENSITIVE )
         return -1;
       rs.last();
       int cnt = rs.getRow();
       rs.beforeFirst();
       return cnt;
     }

Joseph D'silva



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023