I have a program that pulls a large dataset from Oracle 10g (10.2.0.3) using a fairly-straightforward query. You could almost call the query/logic an "export" of sorts in that it selects the columns from a table with a minimal where clause (i.e., it returns most of, if not all, the rows).
The [Java] code is boilerplate that we have all seen:
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = getConnection(Person);
pstmt = con.prepareStatement(
"SELECT ID, FIRST_NAME, LAST_NAME, ... FROM PERSON WHERE ...");
rs = pstmt.executeQuery();
while (rs.next()) {
// write the data to a file
}
}
finally {
if (rs != null) try { rs.close(); } catch (Exception e) { }
if (pstmt != null) try {pstmt.close(); } catch (Exception e) { }
if (con != null) try { con.close() ; } catch (Exception e) { }
}
getConnection is my own method which returns a Connection object to the Oracle database that is used for the "PERSON" table. This feels like a mundane programming question, but I've written code like this numerous times and never had this issue.
I am receiving a java.sql.SQLException: ORA-01406: fetched column value was truncated on the while (rs.next()) line. The Oracle documentation I have read says "a FETCH operation was forced to truncate a character string." It suggests using a larger column buffer to hold the largest column. But this doesn't make sense. In the portion of the above code commented as "write the data to a file" I am simply writing each column as with rs.getBigDecimal("ID"), rs.getString("FIRST_NAME", etc. I can, in fact, reproduce the area using an empty while loop that does nothing with the ResultSet. That is, just iterating through the ResultSet causes the SQLException to be thrown.
The size of the data set returned should be approximately 1million rows. I get the exception after about 600,000 rows/iterations through the loop. Any ideas?