wood burning stoves 2.0*
The moose likes JSP and the fly likes Resultset row count Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Resultset row count " Watch "Resultset row count " New topic
Author

Resultset row count

sumit malik
Greenhorn

Joined: Oct 31, 2001
Posts: 21
How to count the number of rows retreived from the database in resultset.
rudayashanker
Greenhorn

Joined: Oct 25, 2001
Posts: 11
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

Joined: Oct 30, 2001
Posts: 67
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

Joined: Oct 30, 2001
Posts: 67
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
 
Consider Paul's rocket mass heater.
 
subject: Resultset row count