File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Finding number of a rows in a resultset... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Finding number of a rows in a resultset..." Watch "Finding number of a rows in a resultset..." New topic
Author

Finding number of a rows in a resultset...

Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
I'm trying to display data from a table in a jsp page. Instead of running through the resultset in the jsp page itself, I wanted to fill a 2d string array with the values. Well, you must specifiy a size for a 2d string array and I really won't know how many rows I need. Can anybody tell me how I can find the number of rows inside of a resultset? This way I can init my 2d array after I've run my SQL statement and populated the resultset.
Thanks.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Instead of an array, use an ArrayList. Then you don't need to know how long the array is beforehand, because you can add a new element dynamically for each row.
[ July 29, 2003: Message edited by: Ron Newman ]

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Chris Stewart
Ranch Hand

Joined: Sep 14, 2002
Posts: 184
I thought about that, but can it be 2d?
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
You can have an ArrayList of array objects - presumably you know at compile time how many columns you have. (And if you somehow don't, you can also have an ArrayList of ArrayLists.)
Chris Stewart
Ranch Hand

Joined: Sep 14, 2002
Posts: 184
I'm guessing I can do a 4 col string array with 1 row and insert it into an ArrayList. I just wish there was a better way. unno:
[ July 29, 2003: Message edited by: Chris Stewart ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finding number of a rows in a resultset...