From: Peter Kovacs <maxottovonstirlitz@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: PreparedStatement rounds doubles to scale 14 during update
Date: Wed, 5 Sep 2007 11:27:19 +0200
Message-ID: <b6e8f2e80709050227r420d7a3cx751f819fba658854@mail.gmail.com> (raw)
Hi,
I have the following problem with postgresql-8.1-407.jdbc3.jar used
against a 8.1 version backend.
A table "chemterms_cols_test" has a column "logp" defined as:
logp numeric(30,17)
The double value 6.118992224252588 gets rounded to 6.11899222425259000
during updates with PreparedStatements using place-holder. (There is
no rounding with Statement and the value specified in the SQL
literally.) Is this the expected behaviour?
Below is the code that can be used to test this behaviour ("cd_id" is
the primary key):
public static void main(String[] args) {
try {
Connection conn = DBTools.getConnectionHandler().getConnection();
conn.setAutoCommit(false);
int cdId = 1;
double dblValue = 6.118992224252588;
String sql =
"update chemterms_cols_test set logp = ? where cd_id = ?";
try {
PreparedStatement pstmt = conn.prepareStatement(sql);
try {
pstmt.setDouble(1, dblValue);
pstmt.setInt(2, 1);
pstmt.executeUpdate();
conn.commit();
} finally {
pstmt.close();
}
ResultSet rs = null;
sql = "select logp from chemterms_cols_test where cd_id = ?";
pstmt = conn.prepareStatement(sql);
try {
pstmt.setInt(1, 1);
rs = pstmt.executeQuery();
rs.next();
double actual = rs.getDouble(1);
System.out.println("actual=" + actual + ", expected="
+ dblValue + ", equals? : " + (actual == dblValue));
} finally {
try {
if (rs != null) {
rs.close();
}
} finally {
pstmt.close();
}
}
} finally {
conn.close();
}
} catch (Throwable tbl) {
tbl.printStackTrace();
System.exit(1);
}
}
Thanks
Peter
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: maxottovonstirlitz@gmail.com
Subject: Re: PreparedStatement rounds doubles to scale 14 during update
In-Reply-To: <b6e8f2e80709050227r420d7a3cx751f819fba658854@mail.gmail.com>
References: <b6e8f2e80709050227r420d7a3cx751f819fba658854@mail.gmail.com>
* 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