Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
j whiting
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
j whiting
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic