简体   繁体   English

JDBC-ODBC问题-当有值时,Resultset.getString()返回null

[英]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. 首先,这是我在Windows Vista,Windows 7和Windows Server 2008上遇到的问题,但在XP和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. 我知道在Windows Server 2003和Windows Vista之间,Microsoft将MDAC(我们发布的版本为2.8)更改为WDAC 6.0,并且我假设我的问题出现在那些热闹的库中。

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. 我有一个SQL语句:“SELECT TermStates.ActualCoeff FROM TermStates WHERE TermStates.AnalID ='000X'ORDER BY TermStates.indx ASC”返回单列数据,假设没有值可以为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 -1.31182339008657
4.53959374804032 4.53959374804032
8.9828426279767 8.9828426279767
-0.07429423578308 -0.07429423578308
1.90497874662919 1.90497874662919
-0.966443915857118 -0.966443915857118
0.169642057606282 0.169642057606282
-0.825467091179711 -0.825467091179711
-0.206287563886913 -0.206287563886913
-1.00269723837058 -1.00269723837058
-1.30688278976707 -1.30688278976707
0.236262277634983 0.236262277634983
0 0
0 0
0 0
0.108773852550276 0.108773852550276
0 0
0 0
0 -0.0922931225677525 0 -0.0922931225677525
0 0
0.217813798294512 0.217813798294512

And a second set looks like this: 第二组看起来像这样:

-1.63590653334839 -1.63590653334839
-0.959565335083171 -0.959565335083171
9.91635261365054 9.91635261365054
-0.135820145149139 -0.135820145149139
-3.2385711942924 -3.2385711942924
-1.1562654250619 -1.1562654250619
0.174470946581009 0.174470946581009
0 0
0 0
-1.13424407912293 -1.13424407912293
0 0
1.0795237314308 1.0795237314308
0 0
0 0
0 0
0.132662710394659 0.132662710394659
0 0
0 0
0 0
-0.0899603109525667 -0.0899603109525667
0 0
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. 如果返回的数字以“-0.0X”开头,则results.getString()函数将返回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? 有没有人见过JDBC-ODBC桥这样的行为? 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? 是否有任何关于“-0.0X”的位对齐可能表明64位和32位库之间存在问题,或者? Any help you folks have would be appreciated. 任何帮助你的人都将不胜感激。

Chris 克里斯

只需使用results.getDouble(1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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