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\')
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
.
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.