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

I have a problem with a JDBC application using the MONEY data type. When I insert into the MONEY column:

insert into _money_test (amt) values ('123.45')

I have an exception:

Character to numeric conversion error

The same SQL runs from a native Windows application using the ODBC driver. I live in Poland and have Polish, and in my country a comma separates the decimal of the number, so I tried:

insert into _money_test (amt) values ('123,45')

And it worked. I have checked that I have to use PreparedStatement point delimiter: 123.45. And of course I can use:

insert into _money_test (amt) values (123.45)

But some code is "general", it imports data from the csv file, and it was safe to put the number in a string literal.

How to force JDBC to use DBMONEY (or just a dot) in literals?

- WinXP. ODBC JDBC Informix 3.50 TC5/JC5. DBMONEY :

DBMONEY=.

EDIT:

Jython:

import sys
import traceback
from java.sql import DriverManager
from java.lang import Class

Class.forName("com.informix.jdbc.IfxDriver")

QUERY = "insert into _money_test (amt) values ('123.45')"

def test_money(driver, db_url, usr, passwd):
    try:
        print("\n\n%s\n--------------" % (driver))
        db = DriverManager.getConnection(db_url, usr, passwd)
        c = db.createStatement()
        c.execute("delete from _money_test")
        c.execute(QUERY)
        rs = c.executeQuery("select amt from _money_test")
        while (rs.next()):
            print('[%s]' % (rs.getString(1)))
        rs.close()
        c.close()
        db.close()
    except:
        print("there were errors!")
        s = traceback.format_exc()
        sys.stderr.write("%s\n" % (s))



print(QUERY)
test_money("com.informix.jdbc.IfxDriver", 'jdbc:informix-sqli://169.0.1.225:9088/test:informixserver=ol_225;DB_LOCALE=pl_PL.CP1250;CLIENT_LOCALE=pl_PL.CP1250;charSet=CP1250', 'informix', 'passwd')
test_money("sun.jdbc.odbc.JdbcOdbcDriver", 'jdbc:odbc:test', 'informix', 'passwd')

, :

C:\db_examples>jython ifx_jdbc_money.py
insert into _money_test (amt) values ('123,45')


com.informix.jdbc.IfxDriver
--------------
[123.45]


sun.jdbc.odbc.JdbcOdbcDriver
--------------
there were errors!
Traceback (most recent call last):
    File "ifx_jdbc_money.py", line 16, in test_money
        c.execute(QUERY)
SQLException: java.sql.SQLException: [Informix][Informix ODBC Driver][Informix]Character to numeric conversion error


C:\db_examples>jython ifx_jdbc_money.py
insert into _money_test (amt) values ('123.45')


com.informix.jdbc.IfxDriver
--------------
there were errors!
Traceback (most recent call last):
    File "ifx_jdbc_money.py", line 16, in test_money
        c.execute(QUERY)
SQLException: java.sql.SQLException: Character to numeric conversion error



sun.jdbc.odbc.JdbcOdbcDriver
--------------
[123.45]
+2
2

, PreparedStatement. , " " ​​ Informix JDBC.

, , PostgreSQL, , JDBC JDBC-ODBC. , PostgreSQL 123.45. PostgreSQL , . - , .

, DBMONEY=. , (ODBC, JDBC) .

0

Informix JDBC :

java.math.BigDecimal     (, ) 1

, java.math.BigDecimal java.lang.String PreparedStatement#setBigDecimal(), ResultSet#getBigDecimal(), .

"" String BigDecimal, . , toString() BigDecimal.

+2

Source: https://habr.com/ru/post/1745435/


All Articles