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

后端 未结 2 1092
刺人心
刺人心 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.

    0 讨论(0)
  • 2021-01-22 22:33

    I solved this problem by using PreparedStatement. I think that "Character to numeric conversion error" is a bug in Informix JDBC driver.

    In other database I often use, PostgreSQL, there is no difference if I run query via native JDBC driver or via JDBC-ODBC bridge. I found that PostgreSQL do not accept numeric form 123.45. PostgreSQL accepts string literal with dot, but this dot is handled as a thousand separator. The only correctly accepted value is string literal where comma separates decimal part.

    EDIT:

    It can be solved by setting DBMONEY=. on server side, then all connections (ODBC, JDBC) will work with that setting.

    0 讨论(0)
提交回复
热议问题