From: Andrea Aime <aaime@openplans.org>
To: pgsql-jdbc@postgresql.org
Subject: Bug while retrieving money data type from db
Date: Tue, 26 Feb 2008 14:36:07 +0100
Message-ID: <47C415C7.6070200@openplans.org> (raw)
Hi,
I've stumbled into a bug, it seems the driver is not able to
retrive money data type from the db properly unless a getString
is used.... unfortunately in my case the code does not know
what kind of attributes is reading, and it uses getObject instead,
getting back an exception.
Running the attached code all I get is:
Exception in thread "main" org.postgresql.util.PSQLException: Il valore
«1,000.00» non è adeguato al tipo «double».
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.toDouble(AbstractJdbc2ResultSet.java:2645)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getDouble(AbstractJdbc2ResultSet.java:2032)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.internalGetObject(AbstractJdbc2ResultSet.java:134)
at
org.postgresql.jdbc3.AbstractJdbc3ResultSet.internalGetObject(AbstractJdbc3ResultSet.java:39)
at
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getObject(AbstractJdbc2ResultSet.java:2348)
at PgMoneyIssue.main(PgMoneyIssue.java:15)
(translated from italian, "the value 1,000.00 is not adequate for the
type double". Not sure if the problem is locale dependent, since it has
been reported as a GeoServer bug by a user living in USA, and I then
tracked it down to this issue with the driver).
I looked for a bug tracker but could not find one, so here I am, posting
the bug report to the ml.
Contact me back if you need any further information
Cheers
Andrea
Attachments:PgMoneyIssue.java (text/plain, 995B) download
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/*
To run this example run the following sql:
CREATE TABLE testmoney (
id serial,
cost money NOT NULL
);
INSERT INTO testmoney (id, cost) VALUES (1, '$999.00');
INSERT INTO testmoney (id, cost) VALUES (2, '$1,000.00');
INSERT INTO testmoney (id, cost) VALUES (3, '$10,000.01');
and then fix the connection paramters
*/
public class PgMoneyIssue {
public static void main(String[] args) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost/postgis", "username", "password");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from testmoney");
while(rs.next()) {
System.out.println(rs.getObject(1));
System.out.println(rs.getObject(2)); // kaboom on the second record!
}
}
}
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-jdbc@postgresql.org
Cc: aaime@openplans.org
Subject: Re: Bug while retrieving money data type from db
In-Reply-To: <47C415C7.6070200@openplans.org>
References: <47C415C7.6070200@openplans.org>
* 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