I am trying to write an independent database application with JDBC. Now I need a way to extract the top N records from some table. I saw that there is a setMaxRows
method in JDBC, but I donβt feel comfortable using it because I am afraid that the database will pop out all the results and only the JDBC driver will reduce the result. If I need the 5 best results in a table with a billion rows, this will break my neck (the table has a useful index ).
Writing special SQL statements for each type of database is not very pleasant, but it will allow the database to do smart query scheduling and stop receiving more results than necessary.
Can one rely on setMaxRows
to report that the database is not working much?
I think that in the worst case, I cannot rely on this, working to hope. I'm most interested in Postgres 9.1 and Oracle 11.2, so if anyone has experience with these databases, take a step forward.
source share