0

我正在为 Informix 使用 JDBC 驱动程序。我很好地连接到我的主机,但是当执行查询时,我的选择中指定的字段之一返回空值。而不是仅仅检索该值,并且 SQLException 被抛出:

在查询的任何表中都找不到列 (colname)(或 SLV 未定义)。

我以这种方式使用驱动程序:

    try{
    PreparedStatement pstmtDist = conn.prepareStatement(query2);

    ResultSet rsDist = pstmtDist.executeQuery();

    while(rsDist.next()){
            int distCaseId = 0;
            String distCaseIdStr = new String();

            int distCaseDefNum = 0;
            String distCaseDefNumStr = new String();

            distCaseIdStr = rsDist.getObject("colname").toString();
            distCaseId = Integer.parseInt(distCaseIdStr.trim());

            distCaseDefNumStr = rsDist.getObject("colname2").toString();
            distCaseDefNum = Integer.parseInt(distCaseDefNumStr.trim());

            //System.out.println(String.format("distCaseId == %d  distCaseDefNum == %d\n",distCaseId,distCaseDefNum));

    }// end while district cases

    rsDist.close();
    pstmtDist.close();
    connDist.close();

    }
    catch (SQLException e){
            System.out.println("EXCEPTION: "+e.getMessage());


    }

欢迎任何提示!

-TU

4

1 回答 1

0

我认为问题在于:

 distCaseDefNumStr = rsDist.getObject("colname2").toString();

getObject()并且可以返回类似的行null

如果你colname2null值然后getObject()返回null,然后 Java 尝试在对象上运行toString()方法。null

是的,关于 column not found in result 的消息很奇怪,但我认为您确实观察到了空指针异常。的使用getString()getInt()方法ResultSet

于 2013-02-25T11:07:04.830 回答