db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sai Pullabhotla" <Sai.Pullabho...@jMethods.com>
Subject RE: How to get first 'n' rows from table
Date Sun, 27 Jan 2008 19:15:40 GMT
I did see somewhere that the Derby team is actively working on supporting
the LIMIT clause in SELECT statements to limit the number o rows and to
fetch rows in a specific range. 

 

But, for now, if you only want the first N records and never have to process
the next N records, you can do it by setting the maximum rows on the JDBC
Statement object. 

For example: 

 

Statement stmt = connection.createStatement();

stmt.setMaxRows(60);

ResultSet rs = stmt.executeQuery("select * from my_table");

 

At this point, the result set will always contain a maximum of 60 records. 

 

If you do want to process the subsequent records, you need to do it
programmatically by skipping the unwanted records from the resultset. 

 

Hope this helps. 

 

Sai Pullabhotla

President

jMethods, Inc. 

Phone: +1 (402) 408-5753 

Fax: +1 (402) 408-6861

www.jMethods.com 

  _____  

From: visumagic@gmail.com [mailto:visumagic@gmail.com] On Behalf Of
Raghunath
Sent: Sunday, January 27, 2008 12:59 PM
To: derby-user@db.apache.org
Subject: How to get first 'n' rows from table

 

Hi,

 

I want to fetch first 'n' rows from a table of 1000 records. 

 

I have one select query which will result 500 rows.

select * from tablea where info = '---' ;

//500 records..

But I need only n(say 60) records based on user choice.My application is
going to process n records at a time (n value is user choice). In Oracle I
can give rownum=60

then it will fetch only 60 records.

But in derby im search for a way to do this...



-- 
Thanks
Raghunath N


Mime
View raw message