db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marco Rico-Gomez (JIRA)" <j...@apache.org>
Subject [jira] Created: (DERBY-4998) Dynamic values in arithmetic operation must be explicitly casted to decimal when using PreparedStatement
Date Wed, 02 Feb 2011 22:29:29 GMT
Dynamic values in arithmetic operation must be explicitly casted to decimal when using PreparedStatement
--------------------------------------------------------------------------------------------------------

                 Key: DERBY-4998
                 URL: https://issues.apache.org/jira/browse/DERBY-4998
             Project: Derby
          Issue Type: Bug
          Components: JDBC, SQL
    Affects Versions: 10.7.1.1
            Reporter: Marco Rico-Gomez


The following SQL statement works as expected without an error:
---
update T_Professor set weight_In_B_D = ((((weight_In_B_D + 10) - 5) *
4) / 2) where (id = 1)
---

But the same statement as a PreparedStatement throws an exception:
--
update T_Professor set weight_In_B_D = ((((weight_In_B_D + ?) - ?) *
?) / ?) where (id = ?)
--

--
java.sql.SQLException: The resulting value is outside the range for the data type DECIMAL/NUMERIC(31,31).
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
Source)
	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown
Source)
	... 34 more
Caused by: ERROR 22003: The resulting value is outside the range for
the data type DECIMAL/NUMERIC(31,31).
	at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
	at org.apache.derby.iapi.types.SQLDecimal.setWidth(Unknown Source)
	at org.apache.derby.exe.ac0b5b0099x012dxe042x51f3x000000e17f003.e3(Unknown
Source)
	at org.apache.derby.impl.services.reflect.DirectCall.invoke(Unknown Source)
	at org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.doProjection(Unknown
Source)
	at org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.getNextRowCore(Unknown
Source)
	at org.apache.derby.impl.sql.execute.NormalizeResultSet.getNextRowCore(Unknown
Source)
	at org.apache.derby.impl.sql.execute.DMLWriteResultSet.getNextRowCore(Unknown
Source)
	at org.apache.derby.impl.sql.execute.UpdateResultSet.collectAffectedRows(Unknown
Source)
	at org.apache.derby.impl.sql.execute.UpdateResultSet.open(Unknown Source)
	at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown
Source)
	at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
	... 28 more
--
(The connection is made to an embedded in memory instance.)

The values must be explicitly casted to decimal to get it working (even when the values are
set as BigDecimal):
--
update T_Professor set weight_In_B_D = ((((weight_In_B_D + cast(? as decimal)) - cast(? as
decimal)) *
cast(? as decimal)) / cast(? as decimal)) where (id = ?)
--


-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message