0

我正在使用 Tomcat 7、Microsoft SQL Server 2008 RC2 和 JTDS 驱动程序

我实际上也在使用 C3P0 来尝试解决这个问题,但它根本没有区别。我使用的是 Microsoft 的驱动程序,但它给我带来了其他问题(仅转发结果集不支持请求的操作)

我收到以下错误,总是在同一点。在到达这一点之前,我已经成功运行了其他查询:

java.sql.SQLException:无效状态,ResultSet 对象已关闭。在 net.sourceforge.jtds.jdbc.JtdsResultSet.checkOpen(JtdsResultSet.java:287) 在 net.sourceforge.jtds.jdbc.JtdsResultSet.findColumn(JtdsResultSet.java:943) 在 net.sourceforge.jtds.jdbc.JtdsResultSet.getInt (JtdsResultSet.java:968) 在 com.mchange.v2.c3p0.impl.NewProxyResultSet.getInt(NewProxyResultSet.java:2573) 在 com.tt.web.WebPosition.createPosition(WebPosition.java:863)

代码如下:

public static List getListPositions(String query) {
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    List list = null;
    try { //execute the sql query and create the resultSet
        con = DBConnection.getInstance().getConnection();
        stmt = con.createStatement();           
        rs  = stmt.executeQuery(query);
        while(rs.next()) {
            if(rs.isFirst()) {
                list = new ArrayList();
            }
            WebPosition webPos = null;
            webPos = new WebPosition(rs);

            list.add(webPos);
        }           

    } catch (java.sql.SQLException e) {
        System.out.println("SQLException in getListPositions");
        System.out.print(query);
        Log.getInstance().write(query);
        Log.getInstance().write(e.toString());
    } catch (Exception ex) {
        System.out.print(ex);
        ex.printStackTrace();
        Log.getInstance().write(ex.toString());
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                Log.getInstance().write(e.toString());
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                Log.getInstance().write(e.toString());
            }
        }
        DBConnection.getInstance().returnConnection(con);
    }
    return list;
}

public WebPosition(ResultSet rs) {
  createPosition( rs);
}

public void createPosition(ResultSet rs) {
    try {

        this.setCurrentDate4Excel(rs.getString("SYSDATE_4_EXCEL"));
        this.setExerciseType(rs.getInt("EXERCISE_STYLE_CD"));
        ...

代码在上述两行之间失败。

我无法解释为什么结果集会在函数中间关闭(即它会检索 rs.getString("SYSDATE_4_EXCEL") 但随后会因 rs.getInt("EXERCISE_STYLE_CD" ))

有没有人有任何想法?我想这是某种内存问题,并且在一定数量的数据后连接会自动关闭,但我不知道如何解决这个问题。我尝试增加 JVM 的堆大小。

4

0 回答 0