[常见FAQ] websphere6.1对ResultSet强制关闭的问题

aurora 2007-09-21
WebSphere6.1对ResultSet会产生强制的关闭,下面的这部分代码在WebLogic8.1下是没有问题的,但是我将它移植到了WebSphere6.1的环境下,


public static ArrayList getAllRoles(Connection conn) throws SQLException {
    PreparedStatement pstmt = null;
    ArrayList al = new ArrayList();
    String sql = "select role_code,role_name,role_desc from " +
        RoleBean.TB_ROLE
        + " order by role_code";
    try {
      pstmt = conn.prepareStatement(sql);
      ResultSet rs1 = pstmt.executeQuery();
      while (rs1.next()) {
        RoleBean role = new RoleBean(rs1.getString("role_code"),
                                     rs1.getString("role_name"),
                                     rs1.getString("role_desc"),
                                     null);

        role.setPrivList(role.getPrivs(conn));//在这里调用了getPrives(conn)方法,当代码运行到这的时候报错,显示com.ibm.db2.jcc.b.SqlException: [ibm][db2][jcc][10120][10898] 操作无效:已关闭 result set,为什么会出现这个问题?请高手帮助分析一下。先谢谢了。      
al.add(role);
      }
      rs1.close();
      return al;
    }
    catch (SQLException e) {
      throw e;
    }
    finally {
      if (pstmt != null) {
        pstmt.close();
      }
    }


-----------------------
public ArrayList getPrivs(Connection conn) throws SQLException {

    PreparedStatement pstmt = null;
    String sql = "select r.menu_code,p.priv_name , p.tree_level from "
        + this.TB_ROLE_PRIV + " r," + this.SM_PRIV_TB + " p"
        + " where r.role_code='" + this.roleCode + "'"
        + " and r.menu_code = p.priv_no"
        + " order by   menu_code, p.tree_level";
    try {
      Statement stmt = conn.createStatement();

//      ResultSet rs = pstmt.executeQuery();
      ResultSet rs = stmt.executeQuery(sql);
      ArrayList al = new ArrayList();
      while (rs.next()) {
        PrivBean priv = new PrivBean(rs.getString("menu_code"),
                                     rs.getString("priv_name"),
                                     rs.getInt("tree_level"));
        al.add(priv);
      }
      // rs.close();
      return al;
    }
    catch (SQLException e) {
      throw e;
    }
    finally {
      if (pstmt != null) {
        pstmt.close();
      }
    }
aurora 2007-09-26
该问题解决了。
qtlkw 2010-07-11
你用db2吧?设置一下数据源的定制属性就可以, right?
dingdingfm 2010-07-13
楼主,问题出在哪儿,讲出来分享一下吧。thanks!
Global site tag (gtag.js) - Google Analytics