[ http://issues.apache.org/jira/browse/DERBY-1136?page=all ]
Bryan Pendleton updated DERBY-1136:
-----------------------------------
Attachment: derby-1136-resultset-reg-test.diff
Thank you for the information about the SQLDouble change.
Your comment helped me realize that derbynet/prepStmt.java is not the best
location for the regression test, because those tests run only for the network
server environments, not for the embedded environment.
Therefore, I've attached a new patch, 'derby-1136-resultset-reg-test.diff',
which moves the regression test to jdbcapi/resultset.java. The resultset
regression test runs in the embedded environment as well as in the network
server environment.
With this new test, I am able to confirm *both* of your fixes. That is, when I
backed both your fixes out of my sandbox, resultset.java produces the expected
exception failure in both the embedded and DerbyNetClient configurations. Then,
when I restored the SQLDouble.java change, the embedded test works. And when I
restored the CrossConverters.java change, the DerbyNetClient test works. This
makes me much happier about the regression test, since now it confirms both
fixes.
Please let me know of any other comments about this patch.
> JDBC driver on rs.getFloat() gives LossOfPrecisionConversionException for
> float fields containing Float.MAX_VALUE
> -----------------------------------------------------------------------------------------------------------------
>
> Key: DERBY-1136
> URL: http://issues.apache.org/jira/browse/DERBY-1136
> Project: Derby
> Type: Bug
> Components: JDBC
> Versions: 10.1.1.0
> Reporter: Mitesh Meswani
> Attachments: 1136.diff, derby-1136-reg-test.diff,
> derby-1136-resultset-reg-test.diff, test.java
>
> I have a table created in the Derby database with a field as "float". I am
> able to successfully insert into this field the value FLOAT.MAX_VALUE
> (3.4028235E38). But when I try to query this field and try to use
> resultSet.getFloat() to retrieve this value I get a SQLException thrown.
> The derby driver that I am using is the one that is part of our Glassfish
> 9.0 build.
> The stack trace is :
> org.apache.derby.client.am.LossOfPrecisionConversionException: Invalid data
> conversion:Requested conversion would result in a loss of precision of
> 3.4028235E38
> at
> org.apache.derby.client.am.CrossConverters.getFloatFromDouble(Unknown Source)
> at org.apache.derby.client.am.Cursor.getFloat(Unknown Source)
> at org.apache.derby.client.am.ResultSet.getFloat(Unknown Source)
> at DerbyFloat.testFloat(DerbyFloat.java:121)
> at DerbyFloat.main(DerbyFloat.java:139)
> I have attached a simple java program that I have used to reproduce this
> problem.
> import java.sql.*;
> import java.lang.reflect.Method;
> import java.lang.reflect.Modifier;
> public class DerbyFloat {
>
> /* Derby */
> static final String userName = "APP";
> static final String password = "APP";
> static final String connectionURL =
>
> "jdbc:derby://localhost:1527/sun-appserv-samples;retrieveMessagesFromServerOnGetMessage=true;";
> static final String driverName = "org.apache.derby.jdbc.ClientDriver";
> Connection conn;
>
> public DerbyFloat() {}
>
> void init() throws SQLException {
> conn = getConnection(driverName, connectionURL, userName, password);
> }
>
> private static Connection getConnection(String driverName, String
> connectionURL,
> String userName, String password) throws SQLException {
> Connection conn = null;
> try {
> Class.forName (driverName);
> }
> catch (ClassNotFoundException e) {
> System.out.println("Could not load the driver class. Error is " +
> e);
> }
> try {
> conn = DriverManager.getConnection(connectionURL, userName,
> password);
> conn.setAutoCommit(false);
> } catch (SQLException e) {
> System.out.println("Error while getting connection");
> SQLException currentException = e;
> do {
> System.out.println("Exception is" + currentException);
> System.out.println(
> "getMessage()" + currentException.getMessage());
> System.out.println(
> "getErrorCode()" + currentException.getErrorCode());
> System.out.println(
> "getSQLState()" + currentException.getSQLState());
> currentException = currentException.getNextException();
> } while (currentException != null);
> throw e;
> }
> return conn;
> }
>
> public void insertRows() throws java.sql.SQLException {
> PreparedStatement ps;
> try {
> ps = conn.prepareStatement("DROP TABLE DERBYFLOAT");
> ps.executeUpdate();
> } catch (SQLException e) {
> System.out.println("Table does not exist");
> }
>
> ps = conn.prepareStatement("CREATE TABLE DERBYFLOAT (ID INT PRIMARY
> KEY, FLOATDATA FLOAT)");
> // ps = conn.prepareStatement("CREATE TABLE DERBYFLOAT (ID INT
> PRIMARY KEY, FLOATDATA FLOAT(24))");
> ps.executeUpdate();
>
> ps = conn.prepareStatement("DELETE FROM DERBYFLOAT");
> ps.executeUpdate();
> ps = conn.prepareStatement(
> "INSERT INTO DERBYFLOAT(ID, FLOATDATA) VALUES(1, 1)");
> ps.executeUpdate();
> ps = conn.prepareStatement(
> "INSERT INTO DERBYFLOAT(ID, FLOATDATA) VALUES(2,
> 124567890123456)");
> ps.executeUpdate();
> ps = conn.prepareStatement(
> "INSERT INTO DERBYFLOAT(ID, FLOATDATA) VALUES(3, 3.4028235E37)");
> ps.executeUpdate();
> ps = conn.prepareStatement(
> "INSERT INTO DERBYFLOAT(ID, FLOATDATA) VALUES(4, 3.4028235E38)");
> ps.executeUpdate();
>
> }
>
> public void testFloat() throws java.sql.SQLException {
> PreparedStatement ps = conn.prepareStatement(
> "SELECT ID, FLOATDATA FROM DERBYFLOAT");
> ResultSet rs = ps.executeQuery();
> ResultSetMetaData rsmd = rs.getMetaData();
> while(rs.next()) {
> /*
> Object o = rs.getObject(i);
> String columnTypeName = rsmd.getColumnTypeName(i);
> System.out.println("column " + (i) + " type: " +
> columnTypeName +
> " (" + rsmd.getColumnType(i) + ") " + "\t\tJava Type: "
> + o.getClass());
> */
> System.out.println("\n Value of field 1 uing getInt() : " +
> rs.getInt(1));
> try {
> System.out.println("\n Value of field 2 using getFloat()
> : " + rs.getFloat(2));
> } catch (SQLException e) {
> System.out.println("\n Value of field 2 using getFloat()
> resulted in a SQLException");
> e.printStackTrace();
> System.out.println("\n Value of field 2 using
> getObject() : " + rs.getObject(2));
> }
>
> }
>
> }
>
> public static final void main (String args [])
> {
> DerbyFloat dbFloat = new DerbyFloat();
> try {
> dbFloat.init();
> dbFloat.insertRows();
> dbFloat.testFloat();
> } catch (SQLException ex) {
> System.out.println("SQLException : "+ ex);
> ex.printStackTrace();
> }
> }
>
> }
>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira