Search code examples
javaoraclejdbc

Set default fetch size for Oracle JDBC driver without code modification


Background

I'm writing a program that uses Oracle as a database.

I want to change the default fetch size for SQLs for performance, without code modification.

Problem

The program uses SQL in various places, so I want to avoid inserting setFetchSize() before every Statement.executeQuery().

With PostgreSQL or MySQL, you can change the default fetch size with the JDBC URL parameter defaultRowFetchSize. You can set defaultRowFetchSize=100 to improve the performance of DB access.

However, I couldn't find the equivalent for the Oracle JDBC driver.

Question

Is there any way to set the default fetch size for the Oracle JDBC driver without code modification?

Note 1

This program accesses Oracle through DataSource. I can change the JDBC URL. I can also change system properties or environment variables without code modification.

Note 2

The current implementation doesn't use setFetchSize() or Properties to set the default fetch size (it doesn't set any properties to call Statement.executeQuery()).


Solution

  • Yes. You can specify a defaultRowPrefetch property.

    java.util.Properties info = new java.util.Properties();
    info.put ("user", userName);
    info.put ("password", passWord);
    info.put ("defaultRowPrefetch", "15");
    getConnection ("jdbc:oracle:thin:@", info);