Subject Re: [Firebird-Java] setFetchSize
Author Roman Rokytskyy
Hi,

> I am attempting to use setFetchSize to avoid an "out of memory" condition.
> (512M ram)
>
> 28 column table, all VARCHAR (35) or less, name, address, and so forth
>
> Here's the code where I think I should setFetchSize.
> // connect to database with user and password
> connection = DriverManager.getConnection( url, user, password );
> // create Statement to query database
> statement = connection.createStatement(
> resultSet.TYPE_SCROLL_INSENSITIVE,
> resultSet.CONCUR_READ_ONLY );
> statement.setFetchSize(10);
>
> // specify query and execute it
> resultSet = statement.executeQuery( query );
>
> System.out.println( "resultSet worked" );
>
> It never reaches the println statement.
>
> WHAT am I doing wrong here?

setFetchSize(int) method tells the driver how many records should be
fetched from the database at once when next row is needed. However in case
of TYPE_SCROLL_INSENSITIVE the complete result set must be cached in order
to provide scrolling capabilities (Firebird itself does not have this
feature).

The only possibility to limit the number of rows fetched to the client for
you is to use SELECT FIRST n SKIP m <column list> FROM ... statement (n
and m can be parameters). Or use TYPE_FORWARD_ONLY result sets.

Roman