File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

select a range of rows by SQL

 
Sue Stephen
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When a query returns a big resultset of 50000 rows, is it possible to use SQL to limit the rows number like only returning 2000-3000 rows, rather than using "select top 2000". Thank you for your help.


~Sue
 
pradeep jaladi
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
option1
In SqlServer2000 we had that option to display how many rows due we want.

option 2

While getting the data from database fetch the row one by one and add up to the number of row's u want and forward the remaining to next.
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sue,

Try the Statement's getFetchSize(int)

public int getFetchSize()

throws SQLExceptionRetrieves the number of result set rows that is the default fetch size for ResultSet objects generated from this Statement object. If this Statement object has not set a fetch size by calling the method setFetchSize, the return value is implementation-specific.

Returns:
the default fetch size for result sets generated from this Statement object
Throws:
SQLException - if a database access error occurs

java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#setFetchSize(int)

Rgds,

Seetesh
 
Muthu Ponmozhi
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are using jdbc you can use the functions Statement.setFetchSize() and Statement.setMaxRows to limit the no. of rows in a resultset.
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using Oracle you can restrict your data using rownum.

like rownum < 10001...

If you have some other filtering criteria then You can also use rank and dense_rank method of oracle to filter Data
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic