aspose file tools
The moose likes JDBC and the fly likes what is the use of  setFetchSize and  setMaxRows methods in Statement. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "what is the use of  setFetchSize and  setMaxRows methods in Statement." Watch "what is the use of  setFetchSize and  setMaxRows methods in Statement." New topic
Author

what is the use of setFetchSize and setMaxRows methods in Statement.

Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Hi,


what is the use of setFetchSize and setMaxRows methods in Statement?

what is the use of setFetchSize method in ResultSet? ( Already Statement has
setFetchSize method)

thanks,
Thennam Pandian.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

Originally posted by Thennam Pandian:
what is the use of setFetchSize method in ResultSet? ( Already Statement has setFetchSize method)


The answer to the second question comes straight from the ResultSet API:

Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for this ResultSet object ... The default value is set by the Statement object that created the result set.


My Blog: Down Home Country Coding with Scott Selikoff
Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Hi,

Let us take this example. i have 10 Laksh row in a student table.

1. i am using the query "select * from student". By default how many row will be selected by statement obj?

2. Assume that the default value is 50,000. how can i get the remaining rows of the table.

3.what is the difference between fetchSize and setMaxRow?

thanks,
Thennam Pandian.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26157
    
  66

Thennam,
1) All of them
2) The default value of what? maxRows defaults to returning all the rows
3) maxRows is the number of rows that can be returned overall. fetchSize is the number that will be returned in each database roundtrip


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Hi,

can you give me a practical example for both.

thanks,
Thennam
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26157
    
  66

Thennam,
Normally, I wouldn't use either one. If I learned I had a network traffic problem, I might try increasing the fetch size. I would never use maxRows because I prefer limiting the rows from the SQL itself.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Originally posted by Jeanne Boyarsky:
I would never use maxRows because I prefer limiting the rows from the SQL itself.


Since the SQL based 'fetch size' solutions are DB dependent, I guess you could use maxRows if you wanted a DB agnostic solution. Having said that, everyone I know would make the same decision as Jeanne.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: what is the use of setFetchSize and setMaxRows methods in Statement.
 
Similar Threads
How do you know number of rows fetched by ResultSet?.
Query to fetch 100 records in 1000
setFetchSize on preparestatement vs setFetchSize on resultset
How to handle larg ResultSet
Setting max results from query