GeeCON Prague 2014*
The moose likes JDBC and the fly likes limiting the number of rows returned from the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "limiting the number of rows returned from the database" Watch "limiting the number of rows returned from the database" New topic
Author

limiting the number of rows returned from the database

Maitham H
Greenhorn

Joined: Jan 07, 2001
Posts: 29
Hi ,
I need to limit the number of rows returned from the database after executing a query.
for example ,say that i need to see only 5 rows out of my query but the original query returned 30 rows, how can i set this option??
i tried to use the setMaxRows() in the PreparedStatement interface , but it doesn't seems to work , if i use it , i will not get any rows back.
can any one help please.
thanks


A Software life cycle can be greater than its Developer's
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"Maitham H",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in again with a new name which meets the requirements.
Thanks.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
prabhat kumar
Ranch Hand

Joined: Apr 11, 2001
Posts: 114
if u use oracle then a query like this may help u ..
select * from(select * from emp order by sal ) where rownum is < 6(or any other no ...
Maitham H
Greenhorn

Joined: Jan 07, 2001
Posts: 29
I am using InterBase 6.0
I don't think they support the <rownum> attribute.
anyotherideas??
 
GeeCON Prague 2014
 
subject: limiting the number of rows returned from the database