Oracle 10g Thin Driver setFetchSize() can corrupt Data

Recently, we had our application database upgraded from Oracle 9i to Oracle 10g. And therefore we also upgraded oracle jdbc thin driver accordingly.

We were surprised by a nice “ArrayIndexOutOfBoundsException” when reading data from the ResultSet.

After lots of research, I learnt about an inherent bug in Oracle 10g thin driver where if we set the fetchSize on the PreparedStatement we have to set the same fetchSize on the ResultSet as well. This certainly was not the case with previous versions of Oracle.

To my knowledge this bug is not fixed yet. The workaround until then is to set the FetchSize on the ResultSet object whenever you set the FetchSize on the PreparedStatement.

Code snippet:

PreparedStatement ps = conn.prepareStatement(“Select * from some_table”);
ps.setFetchSize(20);
ResultSet rs = rs.executeQuery();
//rs.setFetchSize(20); //Uncomment this line to reproduce the issue.
while (rs.next()) {
// … process the row
}

2 thoughts on “Oracle 10g Thin Driver setFetchSize() can corrupt Data

  1. This issue occurs for Date DataType. Assume that setFetchSize is 11. You should have a tabel with 11 records and all the date values should be null. On reading this field 11th time it gives this exception

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s