I wanted to ask about retrieving the number of rows from ResultSetMetadata(ie, to find out the number of rows a particular database has- the one that is being connected to). I know that getCoulumnCount tells you the number of columns the table has but how would I find out the number of rows because as far as I can see there is no getRowCount method as such? Plaese help!
Nicola Zuliani
Greenhorn
Joined: Feb 26, 2004
Posts: 4
posted
0
Did you try with a "while" which increments a variable? ...or with a query with a COUNT(*)...
Naf Rash
Ranch Hand
Joined: Feb 19, 2004
Posts: 85
posted
0
Do you mean something like while there is another row increment some counter?
leo donahue
Ranch Hand
Joined: Apr 17, 2003
Posts: 327
posted
0
Originally posted by Naf Rash: I wanted to ask about retrieving the number of rows from ResultSetMetadata(ie, to find out the number of rows a particular database has- the one that is being connected to). I know that getCoulumnCount tells you the number of columns the table has but how would I find out the number of rows because as far as I can see there is no getRowCount method as such? Plaese help!
You can use the RowSet Interface which extends java.sql.ResultSet It has a method called getMaxRows().
Thanks, leo
Naf Rash
Ranch Hand
Joined: Feb 19, 2004
Posts: 85
posted
0
I have tried the method getMaxRows but I have read that it: The maxRows limit is the maximum number of rows that a RowSet can contain.
Therefore shouldn't the limit be set first? I have tried to use this method on an object of ResultSet but it isn't being recognised for this. Can you suggest why???
leo donahue
Ranch Hand
Joined: Apr 17, 2003
Posts: 327
posted
0
Originally posted by Naf Rash: I have tried the method getMaxRows but I have read that it: The maxRows limit is the maximum number of rows that a RowSet can contain.
Therefore shouldn't the limit be set first? I have tried to use this method on an object of ResultSet but it isn't being recognised for this. Can you suggest why???
You're right, scratch that last comment. Try this: ResultSet rs = stmt.executeQuery("Select whatever from whatever"); int count = 0; while(rs.next()){ count++; } Just like Nicola suggested.
Jason Steele
Ranch Hand
Joined: Apr 25, 2003
Posts: 100
posted
0
An egg is a chicken's house!
Denna Ramani
Greenhorn
Joined: Feb 28, 2004
Posts: 2
posted
0
hey there, the easy solution is use this query "select count(*) form tablename;" and then read the resultset with getInt(). so it will return number of rows in particular table. Denna
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Finding out the number of rows a database has.