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 JDBC - Max Rows, last() - and LA-LA land 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 "JDBC - Max Rows, last() - and LA-LA land" Watch "JDBC - Max Rows, last() - and LA-LA land" New topic
Author

JDBC - Max Rows, last() - and LA-LA land

j whiting
Greenhorn

Joined: Nov 19, 2004
Posts: 11
Hello,
I was wondering if anyone knows the answer to the following question:
I can use last on my resultset to get the number of rows the query returned, I can call setMaxRows on my PreparedStatement to limit the number of rows returned. Is there any way to get the number of rows a database would have returned if max rows was not set?
I have noticed our database - DB2 to be exact - has done alot of optimization on queries performed - and was hoping that during the compilation of a PreparedStatement it might have some meta data to access - or am i in LA-LA land with this one?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

If your database support sub-queries you can take the original query and wrap it in a query for count. Somthing like:

select count(*) as recordCount from (orginal query goes here)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
j whiting
Greenhorn

Joined: Nov 19, 2004
Posts: 11
ok, gotcha - thank you for that. I was asking if the PreparedStatement i am creating has a max rows (which i set programmaticly - with the setMaxRows(int) method of PreparedStatement) of say 15 - and the results would tend to be in the 100's. What i am asking is if there is a way to determine how many the query WOULD HAVE HAD brought back if not programmaticly set to the 15? Sounds like magic to me.
 
jQuery in Action, 2nd edition
 
subject: JDBC - Max Rows, last() - and LA-LA land
 
Similar Threads
moving cursor to last row in the resultset
Memory leak with MySQL JDBC driver
limiting the number of rows returned from the database
Best way to access large amount of data using JDBC
Validator range and duplicate fields