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 JDBC - Max Rows, last() - and LA-LA land Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
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: 61010
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC - Max Rows, last() - and LA-LA land