You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2014/02/26 12:00:19 UTC
[jira] [Commented] (DERBY-6483) JDBC setObject() on DECIMAL looses
fractional part of value
[ https://issues.apache.org/jira/browse/DERBY-6483?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13912762#comment-13912762 ]
Knut Anders Hatlen commented on DERBY-6483:
-------------------------------------------
I think the observed behaviour is intentional. The [javadoc for java.sql.PreparedStatement.setObject(int, Object, int)|http://download.java.net/jdk8/docs/api/java/sql/PreparedStatement.html#setObject-int-java.lang.Object-int-] says:
{quote}
This method is similar to setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength), except that it assumes a scale of zero.
{quote}
When the scale is zero, there is no fractional part.
> JDBC setObject() on DECIMAL looses fractional part of value
> -----------------------------------------------------------
>
> Key: DERBY-6483
> URL: https://issues.apache.org/jira/browse/DERBY-6483
> Project: Derby
> Issue Type: Bug
> Components: JDBC
> Affects Versions: 10.8.2.2
> Reporter: Craig Chaney
> Priority: Minor
>
> I have a table with a DECIMAL column:
> ij> describe MODEL.WORK_ITEM_BIG_DECIMAL_EXTENSIONS;
> COLUMN_NAME |TYPE_NAME|DEC&|NUM&|COLUM&|COLUMN_DEF|CHAR_OCTE&|IS_NULL&
> ------------------------------------------------------------------------------
> JZ_PARENT_ID |CHAR |NULL|NULL|23 |NULL |46 |NO
> INTERNAL_ID |CHAR |NULL|NULL|23 |NULL |46 |NO
> KEY_COL |VARCHAR |NULL|NULL|250 |NULL |500 |NO
> VALUE |DECIMAL |4 |10 |28 |NULL |NULL |YES
> I use a prepared statement from the following SQL:
> UPDATE MODEL.WORK_ITEM_BIG_DECIMAL_EXTENSIONS SET VALUE = ? WHERE INTERNAL_ID = ?
> I set the first parameter like:
> BigDecimal bd = new BigDecimal("123.456");
> ps.setObject(1, bd, Types.DECIMAL);
> This stores the incorrect value 123.0 into the database.
> It works fine if I do instead:
> ps.setBigDecimal(1, bd);
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)