[hg] main-silver: #239274: com.mysql.jdbc.exceptions.jdbc4.MySQL...

  • From: Libor Fischmeistr < >
  • To:
  • Subject: [hg] main-silver: #239274: com.mysql.jdbc.exceptions.jdbc4.MySQL...
  • Date: Wed, 18 Dec 2013 22:55:03 +0000

changeset 4f6c95c942ce in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/4f6c95c942ce
description:
        #239274: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: 
'18446744073709551615' in column '5' is outside valid range for the datatype 
BIGINT.

diffstat:

 
db.dataview/src/org/netbeans/modules/db/dataview/table/ResultSetTableModel.java
 |   5 +-
 db.dataview/src/org/netbeans/modules/db/dataview/util/DBReadWriteHelper.java 
   |  53 ++++++++-
 2 files changed, 49 insertions(+), 9 deletions(-)

diffs (139 lines):

diff --git 
a/db.dataview/src/org/netbeans/modules/db/dataview/table/ResultSetTableModel.java
 
b/db.dataview/src/org/netbeans/modules/db/dataview/table/ResultSetTableModel.java
--- 
a/db.dataview/src/org/netbeans/modules/db/dataview/table/ResultSetTableModel.java
+++ 
b/db.dataview/src/org/netbeans/modules/db/dataview/table/ResultSetTableModel.java
@@ -46,6 +46,7 @@
 import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeSupport;
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.sql.Blob;
 import java.sql.Clob;
 import java.sql.Date;
@@ -91,7 +92,7 @@
             case -100:
                 return Timestamp.class;
             case Types.BIGINT:
-                return Long.class;
+                return BigInteger.class;
             case Types.DOUBLE:
                 return Double.class;
             case Types.FLOAT:
@@ -103,7 +104,7 @@
             case Types.INTEGER:
             case Types.SMALLINT:
             case Types.TINYINT:
-                return Integer.class;
+                return Long.class;
 
             case Types.CHAR:
             case Types.VARCHAR:
diff --git 
a/db.dataview/src/org/netbeans/modules/db/dataview/util/DBReadWriteHelper.java
 
b/db.dataview/src/org/netbeans/modules/db/dataview/util/DBReadWriteHelper.java
--- 
a/db.dataview/src/org/netbeans/modules/db/dataview/util/DBReadWriteHelper.java
+++ 
b/db.dataview/src/org/netbeans/modules/db/dataview/util/DBReadWriteHelper.java
@@ -46,6 +46,7 @@
 
 import java.io.InputStream;
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.sql.*;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -58,7 +59,9 @@
  * @author Ahimanikya Satapathy
  */
 public class DBReadWriteHelper {
-
+    private static final BigInteger maxUnsignedLong = new 
BigInteger("18446744073709551615");
+    private static final BigInteger maxLong = 
BigInteger.valueOf(Long.MAX_VALUE);
+    private static final BigInteger minLong = 
BigInteger.valueOf(Long.MIN_VALUE);
     private static final long maxUnsignedInt = 4294967295L;
     private static final int maxUnsignedShort = 65535;
     private static final short maxUnsignedByte = 255;
@@ -117,12 +120,24 @@
                 }
             }
             case Types.BIGINT: {
+                try {
                 long ldata = rs.getLong(index);
                 if (rs.wasNull()) {
                     return null;
                 } else {
                     return new Long(ldata);
                 }
+                } catch (java.sql.SQLDataException ex) {
+                    // In case of unsigned BIGINT, long is to small to take 
it
+                    // for now getString is asumed to produce greates 
compatiblity
+                    // The returned string is used to create a BigInteger
+                    String sdata = rs.getString(index);
+                    if (sdata == null) {
+                        return null;
+                    } else {
+                        return new BigInteger(sdata);
+                    }
+                }
             }
             case Types.DOUBLE: {
                 double fdata = rs.getDouble(index);
@@ -162,13 +177,14 @@
                         return new Integer(idata);
                     }
                 } catch (java.sql.SQLDataException ex) {
+                    // in case of an unsigned integer, the java Integer is
+                    // to small to hold it => switch to long in that case
                     long ldata = rs.getLong(index);
                     if (rs.wasNull()) {
                         return null;
                     } else {
                         return new Long(ldata);
                     }
-
                 }
             }
             // JDBC/ODBC bridge JDK1.4 brings back -9 for nvarchar columns in
@@ -284,10 +300,24 @@
                     break;
 
                 case Types.BIGINT:
-                    numberObj = (valueObj instanceof Number)
-                            ? (Number) valueObj
-                            : new Long(valueObj.toString());
-                    ps.setLong(index, numberObj.longValue());
+                    if(valueObj instanceof BigInteger) {
+                        BigInteger biValue = (BigInteger) valueObj;
+                        if(biValue.compareTo(maxLong) > 0 || 
biValue.compareTo(minLong) < 0) {
+                            ps.setString(index, valueObj.toString());
+                        } else {
+                            ps.setLong(index, biValue.longValue());
+                        }
+                    } else if (valueObj instanceof Number) {
+                        Number numberValue = (Number) valueObj;
+                        ps.setLong(index, numberValue.longValue());
+                    } else {
+                        BigInteger biValue = new 
BigInteger(valueObj.toString());
+                        if(biValue.compareTo(maxLong) > 0 || 
biValue.compareTo(minLong) < 0) {
+                            ps.setString(index, valueObj.toString());
+                        } else {
+                            ps.setLong(index, biValue.longValue());
+                        }
+                    }
                     break;
 
                 case Types.NUMERIC:
@@ -416,7 +446,16 @@
                     return TimeType.convert(valueObj);
 
                 case Types.BIGINT:
-                    return valueObj instanceof Long ? valueObj : new 
Long(valueObj.toString());
+                    if(valueObj instanceof Long) {
+                        return valueObj;
+                    } else {
+                        BigInteger value = new 
BigInteger(valueObj.toString());
+                        if(value.compareTo(minLong) < 0  || 
value.compareTo(maxUnsignedLong) > 0) {
+                            throw new NumberFormatException("Illegal value 
for BIGINT");
+                        } else {
+                            return value;
+                        }
+                    }
 
                 case Types.DOUBLE:
                     return valueObj instanceof Double ? valueObj : new 
Double(valueObj.toString());

[hg] main-silver: #239274: com.mysql.jdbc.exceptions.jdbc4.MySQL...

Libor Fischmeistr 12/18/2013

Project Features

About this Project

DB was started in November 2009, is owned by Antonin Nebuzelsky, and has 113 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close