pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: [Jdbc-commits] JDBC and real values returned by Postgres
2+ messages / 2 participants
[nested] [flat]

* Re: [Jdbc-commits] JDBC and real values returned by Postgres
@ 2010-04-28 00:04  Oliver Jowett <oliver@opencloud.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Oliver Jowett @ 2010-04-28 00:04 UTC (permalink / raw)
  To: o.bouiron@isc84.org; h.henoch@isc84.org; +Cc: pgsql-jdbc

Olivier Bouiron wrote:

> Under the psql editor, when I want the sum of these 3 rows, the answer 
> is 5.4.
> But, under Java using the JDBC connector, the answer is 5.399999
> 
> I tried to use an other connector (postgresql-8.2-510.jdbc4) and the 
> problem disapears.

I'd guess that it is due to newer drivers setting extra_float_digits. 
See http://archives.postgresql.org/pgsql-jdbc/2009-05/msg00077.php

-O



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [Jdbc-commits] JDBC and real values returned by Postgres
@ 2010-04-28 07:45  Olivier Bouiron <o.bouiron@isc84.org>
  parent: Oliver Jowett <oliver@opencloud.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Olivier Bouiron @ 2010-04-28 07:45 UTC (permalink / raw)
  To: Oliver Jowett <oliver@opencloud.com>; +Cc: h.henoch@isc84.org; pgsql-jdbc

<!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">&nbsp;&nbsp;&nbsp; public static void main( String[] args ) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; StringBuffer sb = new StringBuffer();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Properties props = new Properties();<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Connexion<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; props.setProperty( "user", "postgres" );<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Connection _connexion = DriverManager.getConnection(
"jdbc:postgresql://127.0.0.1:5432/test", props );<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Create and fill the table<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sb.append( "create temporary table test_oliv (val float);"
);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sb.append( "insert into test_oliv(val) values (1.8);" );<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sb.append( "insert into test_oliv(val) values (1.8);" );<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sb.append( "insert into test_oliv(val) values (1.8);" );<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _connexion.prepareStatement( sb.toString() ).execute();<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Request<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ResultSet rs = _connexion.prepareStatement( "select
sum(val) as t from test_oliv;" ).executeQuery();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rs.next();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println( "Before:" );<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // <b>Responses from jdbc driver: not the same</b>
displayed by the basic psql editor of postgres.<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println( "Value: " + rs.getFloat( "t" ) );<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rs.close();<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </font><font color="#3366ff"><font color="#cc0000">_connexion.prepareStatement(
"SET extra_float_digits=0" ).execute();</font><br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rs = _connexion.prepareStatement( "select sum(val) as t
from test_oliv;" ).executeQuery();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rs.next();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println( "After:" );<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // <b>Responses from jdbc driver: the same</b> displayed
by the basic psql editor of postgres.<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println( "Value: " + rs.getFloat( "t" ) );<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rs.close();<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _connexion.close();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } catch ( Exception e ) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e.printStackTrace();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
</font><br>
Regards<br>
<br>
Olivier Bouiron<br>
<br>
Le 28/04/2010 02:04, Oliver Jowett a &eacute;crit&nbsp;:
<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>



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2010-04-28 07:45 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-04-28 00:04 Re: [Jdbc-commits] JDBC and real values returned by Postgres Oliver Jowett <oliver@opencloud.com>
2010-04-28 07:45 ` Olivier Bouiron <o.bouiron@isc84.org>

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