简体   繁体   中英

JDBC-ODBC issue - Resultset.getString() returning null when there is a value

To begin, this is a problem that I am having on Windows Vista, Windows 7, and Windows Server 2008, but not on XP and Server 2003.

I am aware that between Windows Server 2003 and Windows Vista, Microsoft changed MDAC (we were shipping version 2.8) to WDAC 6.0, and I am assuming that my issue lies somewhere in that steaming pile of libraries.

I have an SQL statement: "SELECT TermStates.ActualCoeff FROM TermStates WHERE TermStates.AnalID = '000X' ORDER BY TermStates.indx ASC" which returns a single column of data, where it is assumed no values can be Null. These values are high precision, and most are quite small (ie. close to zero) and can also be negative.

The first set of data values looks like this:

-1.31182339008657
4.53959374804032
8.9828426279767
-0.07429423578308
1.90497874662919
-0.966443915857118
0.169642057606282
-0.825467091179711
-0.206287563886913
-1.00269723837058
-1.30688278976707
0.236262277634983
0
0
0
0.108773852550276
0
0
0 -0.0922931225677525
0
0.217813798294512

And a second set looks like this:

-1.63590653334839
-0.959565335083171
9.91635261365054
-0.135820145149139
-3.2385711942924
-1.1562654250619
0.174470946581009
0
0
-1.13424407912293
0
1.0795237314308
0
0
0
0.132662710394659
0
0
0
-0.0899603109525667
0
0

There are many more columns of data, and they all exhibit the same issue. If the number being returned starts with "-0.0X", the results.getString() function will return null.

The basic code looks like this:

results = statement.executeQuery(sql);
if(results != null)
{
    ResultSetMetaData metaData = results.getMetaData();
    ArrayList rowList = new ArrayList();

    String colType = metaData.getColumnTypeName(1);
    Object obj = null;
    if(colType.equals("DOUBLE"))
    {
        obj = null;
        String fValue = results.getString(1);
        if(fValue != null && fValue.length() > 0)
        {
            obj = new Double(fValue);
        }
        else
        {
            obj = new Double(0.0);
        }
    }
    else
    {
        obj = results.getString(1);
    }
    rowList.add(obj);
}

Has anyone ever seen behavior like this with the JDBC-ODBC bridge? I've been working in this environment for many years without any issues, but this one has me stumped. Is there anything about the bit alignment of "-0.0X" that might indicate a problem between 64 and 32 bit libraries, or? Any help you folks have would be appreciated.

Chris

只需使用results.getDouble(1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM