Re: JDBC 9.2: multiple execution of prepared statement-query delivers different double precision results via getString()

Поиск
Список
Период
Сортировка
От Mikko Tiihonen
Тема Re: JDBC 9.2: multiple execution of prepared statement-query delivers different double precision results via getString()
Дата
Msg-id 56318f6405134b7faed245cea972e928@AMSPR07MB018.eurprd07.prod.outlook.com
обсуждение исходный текст
Ответ на JDBC 9.2: multiple execution of prepared statement-query delivers different double precision results via getString()  ("Tilman Sandig" <info@sandig.com>)
Ответы Re: JDBC 9.2: multiple execution of prepared statement-query delivers different double precision results via getString()  ("Tilman Sandig" <info@sandig.com>)
Список pgsql-jdbc
The first few times the driver requests the server to return "1 as double precision" as a text value (thus using server
sidetoString function). 

After that the driver evaluates the actual types of the columns and requests the server to send the value in binary
format.Your toString method will then invoke Double(1).toString on your client side. 

If you modify your code to do
  System.out.println("Value: " + rs.getDouble(1));
the result should not change as statements change column values to binary data encoding.

I do not think the driver can make guarantees about the format of getString values, unless the original database field
istextual. 

-Mikko
________________________________________
From: pgsql-jdbc-owner@postgresql.org <pgsql-jdbc-owner@postgresql.org> on behalf of Tilman Sandig <info@sandig.com>
Sent: 13 September 2013 18:44
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] JDBC 9.2: multiple execution of prepared statement-query delivers different double precision results
viagetString() 

Hello,

there might be a problem in the latest JDBC-driver (9.2 build 1003) when querying double precision-result columns
multipletimes 
and retrieving the result with ResultSet.getString():

The first five queries work as expected, further calls append ".0" to the result-string.

Here is a sample code:

PreparedStatement stmt = myConnection.prepareStatement("select cast(1 as double precision)");
for (int x=0;x<12;x++){
    ResultSet rs = stmt.executeQuery();
    while (rs.next()){
        System.out.println("Value: " + rs.getString(1));
    }
}

-------
Output:
-------

Value: 1
Value: 1
Value: 1
Value: 1
Value: 1
Value: 1.0
Value: 1.0
Value: 1.0
Value: 1.0
Value: 1.0
Value: 1.0
Value: 1.0


The problem does not occur when using JDBC-driver version 9.1;
I use PostgreSQL Version 9.3.0 (Win64/Vista)

Best regards,
  Tilman Sandig



--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Tilman Sandig"
Дата:
Сообщение: JDBC 9.2: multiple execution of prepared statement-query delivers different double precision results via getString()
Следующее
От: "Tilman Sandig"
Дата:
Сообщение: Re: JDBC 9.2: multiple execution of prepared statement-query delivers different double precision results via getString()