Problem with Informix JDBC, MONEY and decimal separator in string literals

后端 未结 2 1098
刺人心
刺人心 2021-01-22 21:57

I have problem with JDBC application that uses MONEY data type. When I insert into MONEY column:

insert into _money_test (amt) values (\'123.45\')
2条回答
  •  感动是毒
    2021-01-22 22:19

    The Informix JDBC data type mapping documentation says the following:

    java.math.BigDecimal           MONEY(p,s)1

    Thus, you need to use java.math.BigDecimal instead of java.lang.String to represent the value, PreparedStatement#setBigDecimal() to set the value and ResultSet#getBigDecimal() to get the value.

    You can "convert" from String to BigDecimal by just passing it as constructor argument. The other way round can be done by calling the toString() method of BigDecimal.

提交回复
热议问题