This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet" Watch "ResultSet" New topic
Author

ResultSet

lape show
Greenhorn

Joined: Feb 07, 2010
Posts: 6
Please how can i get the number of rows returned by a resultset. i need to pass data retrieved from SQL into an array then to the table model and finally to the jtable, but i need to know the size of the array.


lape
Brian Enochson
Greenhorn

Joined: Apr 12, 2011
Posts: 14

This has been covered. http://www.coderanch.com/t/303346/JDBC/java/find-number-rows-resultset.

What you can also do is a select count with an identical where clause to your where used for the actual select?

Lastly, instead of using an array where you need to allocate it, add your results from your result set to an ArrayList as it will grow dynamically.

Brian

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37879
    
  22
. . . and welcome to the Ranch, both of you
lape show
Greenhorn

Joined: Feb 07, 2010
Posts: 6
Thanks a bunch!!!
Brian Enochson
Greenhorn

Joined: Apr 12, 2011
Posts: 14

Thank you.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ResultSet
 
Similar Threads
returning a ResultSet?
Passing VARRAYS to Java
Display Data Records in Table
Resultsets survives failure
SQL Array Question