From: Thomas Kellerer <spam_eater@gmx.net>
To: Dave Cramer <davecramer@gmail.com>
To: Suwalka, Kriti <ksuwalka@informatica.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: JDBC Driver42.2.2 throws error when dealing with money datatype
Date: Tue, 5 Jun 2018 08:19:01 +0200
Message-ID: <56dea0e3-64a6-5023-5bb8-a6d2072fd7d7@gmx.net> (raw)
In-Reply-To: <CADK3HHJTdXbxh1Uusw9EOK2AqWxtGEBR3kcX90R4L6a04XhLNQ@mail.gmail.com>
References: <BN6PR03MB32840C1B2BFC856AEE72390BC7670@BN6PR03MB3284.namprd03.prod.outlook.com>
<CADK3HHJTdXbxh1Uusw9EOK2AqWxtGEBR3kcX90R4L6a04XhLNQ@mail.gmail.com>
This has been discussed on the JDBC mailing list before (and belongs there) and as far as I can tell has never worked properly:
https://www.postgresql.org/message-id/flat/9322.1322663810%40sss.pgh.pa.us#9322.1322663810@sss.pgh.p...https://www.postgresql.org/message-id/flat/4B99F6E9.7000407%40wp.pl#4B99F6E9.7000407@wp.plhttps://www.postgresql.org/message-id/flat/7fbead4f-1375-40b9-8a5b-95d3a1a5e5a5%40e23g2000prf.google...https://www.postgresql.org/message-id/flat/47C415C7.6070200%40openplans.org#47C415C7.6070200@openpla...
Isn't this caused by the fact that the server sends a "formatted" string including the currency symbol, decimal symbol and grouping symbols?
But Double.parseDouble(String) can't parse such a String
And I do agree with the recommendations in some of the above threads: do not use the money data type.
For all intents and purposes numeric is a much better choice.
Thomas
Dave Cramer schrieb am 04.06.2018 um 20:01:
> Hello,
>
> Well that truly is a bug, and shouldn't happen.
>
> Thanks
>
> Dave Cramer
>
> On 4 June 2018 at 11:47, Suwalka, Kriti <ksuwalka@informatica.com <mailto:ksuwalka@informatica.com>> wrote:
>
> Hi,____
>
> __ __
>
> I was trying to read a table with money column using JDBC driver(version 42.2.2). JDBC driver returns data type as double and it internally tries to use ResultSet.getDouble when ResultSet.getObject() is used.____
>
> __ __
>
> Please find the details below____
>
> Database version : 9.6____
>
> Driver version : 42.2.2____
>
> Table DDL: create table src_money(col1 money);____
>
> Insert DML : insert into src_money values(1000);____
>
> __ __
>
> JDBC Code Snippet:____
>
> String sqlQuery= "select * from src_money";____
>
> PreparedStatement stmt= con.prepareStatement(sqlQuery);____
>
> ResultSet readRs= stmt.executeQuery();____
>
> *while*(readRs.next()) {____
>
> System.*/out/*.println(readRs.getObject(1));____
>
> } ____
>
> __ __
>
> JDBC Code Output:____
>
> _org.postgresql.util.PSQLException_: Bad value for type double : 1,000.00____
>
> at org.postgresql.jdbc.PgResultSet.toDouble(_PgResultSet.java:2930_)____
>
> at org.postgresql.jdbc.PgResultSet.getDouble(_PgResultSet.java:2317_)____
>
> at org.postgresql.jdbc.PgResultSet.internalGetObject(_PgResultSet.java:194_)____
>
> at org.postgresql.jdbc.PgResultSet.getObject(_PgResultSet.java:2568_)____
>
> at jdbc_sample_latest.PostgresSSL.main(_PostgresSSL.java:74_)____
>
> __ __
>
> What is the fix or work-around here to get rid of this error? My application is a generic application and I expected that driver would take care of retrieving money data type when using ResultSet.getObject() but unfortunately driver isn’t working as expected.____
>
> __ __
>
> P.S.> I have seen the discussion on the same issue on forum but couldn’t find a solution for the same.____
>
> __ __
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: spam_eater@gmx.net, davecramer@gmail.com, ksuwalka@informatica.com
Subject: Re: JDBC Driver42.2.2 throws error when dealing with money datatype
In-Reply-To: <56dea0e3-64a6-5023-5bb8-a6d2072fd7d7@gmx.net>
References: <BN6PR03MB32840C1B2BFC856AEE72390BC7670@BN6PR03MB3284.namprd03.prod.outlook.com> <CADK3HHJTdXbxh1Uusw9EOK2AqWxtGEBR3kcX90R4L6a04XhLNQ@mail.gmail.com> <56dea0e3-64a6-5023-5bb8-a6d2072fd7d7@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox