The Artima Developer Community
Sponsored Link

Java Answers Forum
Total Rows in ResultSet

3 replies on 1 page. Most recent reply: Nov 8, 2002 3:28 PM by Daniel Ray

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Babu Reddy

Posts: 7
Nickname: babureddy
Registered: Jun, 2002

Total Rows in ResultSet Posted: Nov 8, 2002 1:39 AM
Reply to this message Reply
Advertisement
How can we find the total number of rows in
the Resultset with out traversing the resultset
so that i can prepare a String array of size equal to
that if the size and store all the values .

Thanks in Advance


Ramu

Posts: 29
Nickname: sripoorna
Registered: Oct, 2002

Re: Total Rows in ResultSet Posted: Nov 8, 2002 4:34 AM
Reply to this message Reply
hi,

There is no direct method to find the size of the result set. so for that we have to explicitly run this query "SELECT COUNT(*) FROM <TABLE NAME>" before doing any operions. for that use the following code

String str_Query = "SELECT COUNT(*) FROM <TABLE NAME>";
Statement stmt = con.createStatement();
ResultSet rs = stmt.execute(str_Query);
rs.next();
int count = rs.getInt(1);
rs.close();
st.close();

regards
ramu

Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: Total Rows in ResultSet Posted: Nov 8, 2002 2:57 PM
Reply to this message Reply
You can also cast the ResultSet to a CachedRowSet which has a size() method.

Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: Total Rows in ResultSet Posted: Nov 8, 2002 3:28 PM
Reply to this message Reply
Oh yeah. You would need rowset.jar from sun to use that. Sorry about that.

Flat View: This topic has 3 replies on 1 page
Topic: cookies and java Previous Topic   Next Topic Topic: Converting String to int

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use