• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Resultset row count

 
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.
 
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
 
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
 
Your mother is a hamster and your father smells of tiny ads!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic