useCursorFetch=true impacts getFloat() values.
Posted by: Zhang Garriot
Date: October 09, 2018 09:56PM

I encountered a strange JDBC case when I use float values with the connection property useCursorFetch. Setting useCursorFetch to true/false makes getFloat() returning different values with different precision.

Reproduce:
1. Create a table:

CREATE TABLE data_type(
col_float float
);

2. Insert data: (I know float is a single precision type, but in our case, double values are inserted)

INSERT INTO data_type(col_float) VALUES(358294.648941);
INSERT INTO data_type(col_float) VALUES(120263.815023);

3. JAVA code:

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useCursorFetch=false", "user", "password");
PreparedStatement statement = con.prepareStatement("select col_float from data_type;");

System.out.println("Executing query...");
ResultSet rs = statement.executeQuery();
while (rs.next()) {
System.out.println(rs.getDouble(1) );
}

rs.close();
statement.close();
con.close();

When useCursorFetch=false, I got the following output in the console:
358295.0
120264.0

But when I set useCursorFetch=true, I got different values in the console:
358294.66
120263.81


Could somebody please explain why useCursorFetch impacts the values?

Thank you very much.

Options: ReplyQuote


Subject
Written By
Posted
useCursorFetch=true impacts getFloat() values.
October 09, 2018 09:56PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.