pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hervé Hénoch <h.henoch@isc84.org>
To: pgsql-jdbc@postgresql.org
Subject: Postgresql8.4 + floats with jdbc driver postgresql-8.4-701.jdbc4.jar
Date: Mon, 26 Apr 2010 15:48:22 +0200
Message-ID: <4BD599A6.9080504@isc84.org> (raw)

Hello,

We have a strange behavior when running this code :

public static void main(String[] args) {

        try {
            Class.forName("org.postgresql.Driver");
            Properties props = new Properties();
            props.setProperty("user", "postgres");
            props.setProperty("password", "mypassword");
            Connection _connexion = DriverManager.getConnection(
                    "jdbc:postgresql://<ip>:5432/personnel", props);

            _connexion
                    .prepareStatement(
                            "create temporary table test_oliv (val 
real);insert into test_oliv(val) values (1.8);"
                                    + "insert into test_oliv(val) values 
(1.8);insert into test_oliv(val) values (1.8);")
                    .execute();

            ResultSet rs = _connexion.prepareStatement(
                    "select sum(val) as t from test_oliv;").executeQuery();
            rs.next();
            System.out.println("Float: " + rs.getFloat("t"));
            System.out.println("Double: " + rs.getDouble("t"));
            System.out.println("Object: " + rs.getObject("t"));

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

The results are :

Float: 5.3999996
Double: 5.3999996
Object: 5.3999996

With 8.2 driver the results are rights.

Idea ?

Regards



Message-ID: <4BD599A6.9080504@isc84.org>
Permalink:  ../4BD599A6.9080504@isc84.org/
Also on:    postgresql.org/message-id/4BD599A6.9080504@isc84.org

 · 

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: h.henoch@isc84.org
  Subject: Re: Postgresql8.4 + floats with jdbc driver postgresql-8.4-701.jdbc4.jar
  In-Reply-To: <4BD599A6.9080504@isc84.org>
  References: <4BD599A6.9080504@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