pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Olivier Bouiron <o.bouiron@isc84.org>
To: Oliver Jowett <oliver@opencloud.com>
Cc: h.henoch@isc84.org
Cc: PostgreSQL - JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: [Jdbc-commits] JDBC and real values returned by Postgres
Date: Wed, 28 Apr 2010 09:45:11 +0200
Message-ID: <4BD7E787.8080703@isc84.org> (raw )
In-Reply-To: <4BD77B70.40603@opencloud.com >
References: <4BD69D2D.3030508@isc84.org >
<4BD77B70.40603@opencloud.com >
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
Thanks, you resolved my problem!<br>
<br>
If it can help someone, this is how to do:<br>
<br>
<font color="#3366ff"> public static void main( String[] args ) {<br>
try {<br>
StringBuffer sb = new StringBuffer();<br>
Properties props = new Properties();<br>
<br>
// Connexion<br>
props.setProperty( "user", "postgres" );<br>
Connection _connexion = DriverManager.getConnection(
"jdbc:postgresql://127.0.0.1:5432/test", props );<br>
// Create and fill the table<br>
sb.append( "create temporary table test_oliv (val float);"
);<br>
sb.append( "insert into test_oliv(val) values (1.8);" );<br>
sb.append( "insert into test_oliv(val) values (1.8);" );<br>
sb.append( "insert into test_oliv(val) values (1.8);" );<br>
_connexion.prepareStatement( sb.toString() ).execute();<br>
<br>
// Request<br>
ResultSet rs = _connexion.prepareStatement( "select
sum(val) as t from test_oliv;" ).executeQuery();<br>
rs.next();<br>
System.out.println( "Before:" );<br>
// <b>Responses from jdbc driver: not the same</b>
displayed by the basic psql editor of postgres.<br>
System.out.println( "Value: " + rs.getFloat( "t" ) );<br>
rs.close();<br>
<br>
</font><font color="#3366ff"><font color="#cc0000">_connexion.prepareStatement(
"SET extra_float_digits=0" ).execute();</font><br>
rs = _connexion.prepareStatement( "select sum(val) as t
from test_oliv;" ).executeQuery();<br>
rs.next();<br>
System.out.println( "After:" );<br>
// <b>Responses from jdbc driver: the same</b> displayed
by the basic psql editor of postgres.<br>
System.out.println( "Value: " + rs.getFloat( "t" ) );<br>
<br>
rs.close();<br>
<br>
_connexion.close();<br>
} catch ( Exception e ) {<br>
e.printStackTrace();<br>
}<br>
}<br>
</font><br>
Regards<br>
<br>
Olivier Bouiron<br>
<br>
Le 28/04/2010 02:04, Oliver Jowett a écrit :
<blockquote cite="mid:4BD77B70.40603@opencloud.com" type="cite">Olivier
Bouiron wrote:
<br>
<br>
<blockquote type="cite">Under the psql editor, when I want the sum of
these 3 rows, the answer is 5.4.
<br>
But, under Java using the JDBC connector, the answer is 5.399999
<br>
<br>
I tried to use an other connector (postgresql-8.2-510.jdbc4) and the
problem disapears.
<br>
</blockquote>
<br>
I'd guess that it is due to newer drivers setting extra_float_digits.
See <a class="moz-txt-link-freetext" href="http://archives.postgresql.org/pgsql-jdbc/2009-05/msg00077.php">http://archives.postgresql.or... ;
<br>
<br>
-O
<br>
<br>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Olivier Bouiron
Institut Sainte Catherine
1750, chemin du lavarin
84000 AVIGNON
Tel: 04.90.27.57.43
</pre>
</body>
</html>
view thread (2+ messages)
Message-ID: <4BD7E787.8080703@isc84.org>
Permalink: ../4BD7E787.8080703@isc84.org/
Also on: postgresql.org/message-id/4BD7E787.8080703@isc84.org
copy link · copy postgr.es
reply 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: o.bouiron@isc84.org, oliver@opencloud.com, h.henoch@isc84.org
Subject: Re: [Jdbc-commits] JDBC and real values returned by Postgres
In-Reply-To: <4BD7E787.8080703@isc84.org>
References: <4BD69D2D.3030508@isc84.org> <4BD77B70.40603@opencloud.com> <4BD7E787.8080703@isc84.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