I am using spring-2.5.6 to connect from a standalone application to an Oracle 10g database (ojdbc14.jar) using the org.apache.commons.dbcp.BasicDataSource. When I try to retrieve a SqlRowSet using the public SqlRowSet queryForRowSet(String sql, Object[] args) throws DataAccessException method I am getting an ‘java.sql.SQLException: Invalid scale size. Cannot be less than zero’.
The sql calling the table is:
select CUSTAREADESC, BEGCOL, COLLENGTH from CUSTOMERAREA where upper(trim(FLEET)) = upper(trim(?)) and CUSTAREANO = ?
The columns BEGCOL and COLLENGTH are of the data type number with no precision defined.
I found some information on this issue, seems to be an incompatibility between the Oracle drivers and Sun’s implementation of the com.sun.rowset.CachedRowSetImpl.
Using queryForRowSet with subquery factoring SQL gives errors
They suggest changing the sql to the following as a work around.
select CUSTAREADESC, (BEGCOL + 0) BEGCOL, (COLLENGTH + 0) COLLENGTH from CUSTOMERAREA where upper(trim(FLEET)) = upper(trim(?)) and CUSTAREANO = ?
Does anyone know of a better generic solution that doesn’t involve custom sql for any existing table where a column doesn’t have precision defined?
I ended up creating an ResultSetExctractor class that implements ResultSetExtractor and used that to get an OracleCachedRowSet implementation of SqlRowSet. To use this you will need to include the oracle driver jar in your project (used ojdbc14.jar).
This is then used by in the following way to extract a SqlRowSet.