Description:
com.mysql.jdbc.ResultSet.getDoubleInternal does not parse positive and infinite java.lang.Double.POSITIVE_INFINITY java.lang.Double.NEGATIVE_INFINITY
an attempt to read such value gives an error (MySQL-3.23.58-2, but other versions also)
SQLPoll: error: (Bad format for number '-inf' in column 29.).
java.sql.SQLException: Bad format for number '-inf' in column 29.
at com.mysql.jdbc.ResultSet.getDoubleInternal(ResultSet.java:3786)
at com.mysql.jdbc.ResultSet.getDoubleInternal(ResultSet.java:3737)
at com.mysql.jdbc.ResultSet.getDouble(ResultSet.java:1002)
at com.gromco.test.Test.$SearchFreelanceAd.process(Test.java:155)
at com.gromco.sql.SQLPoll.executeSeveralQueries(SQLPoll.java:371)
at com.gromco.sql.SQLPoll.executeQuery(SQLPoll.java:308)
org/gjt/mm/mysql/ jdbc driver has this problem fixed for a long time.
Compare ResultSet from com/mysql/jdbc/ and org/gjt/mm/mysql/
where the code checkes the data first for nan, then for inf and -inf, and only then for
regular number. You need to add these checkes becfore marked line:
------------ mysql-connector-java-3.2.0-alpha/com/mysql/jdbc/ResultSet.java
protected double getDoubleInternal(String stringVal, int colIndex)
throws SQLException {
try {
if ((stringVal == null) || (stringVal.length() == 0)) {
return 0;
}
double d = Double.parseDouble(stringVal); <-------- Error here
// The stringVal may be -inf, inf and nan. jdbc drive does not handle it
------------ end of sample ------------------
----------- mm.mysql-2.0.4/org/gjt/mm/mysql/ResultSet.java
public static double getDouble(byte[] buf)
{
double value = 0;
int exp = 0;
int sign = 1;
int pos = 0;
int len = buf.length;
// remove leading spaces, we may have them wit Inf.
for(;pos<len&&(char)buf[pos]==' ';) pos++;
if(pos+3==len) {
if(((char)buf[pos] == 'N' || (char)buf[pos] == 'n')&&
((char)buf[pos+1] == 'A' || (char)buf[pos+1] == 'a')&&
((char)buf[pos+2] == 'N' || (char)buf[pos+2] == 'n')) {
return Double.NaN;
}
}
if (pos<len) {
if ((char)buf[pos] == '-') {
sign = -1;
pos++;
}
}
for (;pos < len; pos++) {
char ch = (char)buf[pos];
if (ch >= '0' && ch <= '9') {
value = 10 * value + ch - '0';
}
else if (pos + 3 == len) {
if (((char)buf[pos] == 'I' || (char)buf[pos] == 'i')&&
((char)buf[pos+1] == 'N' || (char)buf[pos+1] == 'n')&&
((char)buf[pos+2] == 'F' || (char)buf[pos+2] == 'f')) {
if (sign > 0) {
return Double.POSITIVE_INFINITY;
}
else {
return Double.NEGATIVE_INFINITY;
}
}
---------- end of mm.mysql-2.0.4/org/gjt/mm/mysql/ResultSet.java
How to repeat:
create a table with double field,
do
update test_table set d=-1.4e+390 ;
and then read test_table.d via jdbc.
internally mysql would convert the value -1.4e+390 to negative infinity what would fail as in trace above (`-inf' message)