我收到以下错误:

java.lang.NullPointerException
    at oracle.jdbc.driver.ScrollableResultSet.cacheRowAt(ScrollableResultSet.java:2086)
    at oracle.jdbc.driver.ScrollableResultSet.isValidRow(ScrollableResultSet.java:2060)
    at oracle.jdbc.driver.ScrollableResultSet.next(ScrollableResultSet.java:347)
    at website.web.InboxReader.getkeywordImportance(InboxReader.java:832)
    at website.web.InboxReader.main(InboxReader.java:54)


53表中有Mail行,而1表中有keyword行。在调试时,一旦执行该行kstmt.executeUpdate("UPDATE KEYWORD SET IMPORTANCE = IMPORTANCE + 1.0 WHERE SKEYWORD = '" + s2 + "'");,它将再次进入keyword set.next()并引发异常。

这是代码:

Connection connection = connectToDatabase();
        Statement mstmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        String s1,s2;
        ResultSet mailset = mstmt.executeQuery("SELECT * from MAIL");
        System.out.println("hello in getImportance beg");
        //mailset.beforeFirst();
        while(mailset.next())
        {
            System.out.println("hello in first while");
            Statement kstmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ResultSet keywordset = kstmt.executeQuery("SELECT * FROM KEYWORD");
            while(keywordset.next())
            {
                s1=mailset.getString("SUBJECT");
                System.out.println("Subject: "+s1);
                s2=keywordset.getString("SKEYWORD");
                System.out.println("Keyword: "+s2);
                if(s1.contains(s2))
                {
                    System.out.println("hello in if");
                    kstmt.executeUpdate("UPDATE KEYWORD SET IMPORTANCE = IMPORTANCE + 1.0 WHERE SKEYWORD = '" + s2 + "'");

                }
            }
            keywordset.close();
        }
        mailset.close();
        connection.close();


谢谢!

最佳答案

如果您看一下这条线,那似乎是有问题的:

kstmt.executeUpdate("UPDATE KEYWORD SET IMPORTANCE ='" + (keywordset.getFloat("IMPORTANCE") + 1.0) + "'");

您应该仔细检查电话

keywordset.getFloat("IMPORTANCE")

这最有可能是由于以下事实:记录的列重要性为空或该列可能不存在。只是为了调试您尝试

keywordset.getFloat(0);

或您知道存在哪个列的ID,以查看调用是否有效。

您是否尝试过删除COMMIT语句?因为通常除非您另外指定,否则数据将自动提交,因此无需在语句后调用提交,并且如果将auto_commit指定为false,则提交时应该执行con.commit()而不是通过update语句调用

10-05 18:29