• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resultset row count

 
sumit malik
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to count the number of rows retreived from the database in resultset.
 
rudayashanker
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi this code may help u

code
-----
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc:shank","shankar","shankar");
Statement statement = con.createStatement();
String[] values = {"yes"};
int a = values.length;
for(int i = 0; i < a; ++i)
{
//out.println("values[i]" +values[i]);
String sqlqlab = "Select count(*) from VOTE where notify ="+ "'" + values[i] +"'";
ResultSet intCount= statement.executeQuery(sqlqlab);
int k =0;
if (intCount.next())
{
String b = (values[i] + " owns " + intCount.getString(1) + " tables." +"<br>");
//out.println(b);
k = Integer.parseInt(b);
out.println("k" +k);

}//If Loop
}//For Loop
}//Try Block
 
Francois Bourgault
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use the following code:
ResultSet myResultSet = stmt.executeQuery();

myResultSet.last(); // position on last row
rowcnt = myResultSet.getRow(); // get row no.
myResultSet.beforeFirst(); // reposition on 1st row

Francois
 
Francois Bourgault
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use the following code:
ResultSet myResultSet = stmt.executeQuery();

myResultSet.last(); // position on last row
rowcnt = myResultSet.getRow(); // get row no.
myResultSet.beforeFirst(); // reposition on 1st row

Francois
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic