#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    15
    Rep Power
    0

    Angry java.sql.SQLException: ResultSet is closed


    Hi, I have a web application with a jsp page which has a grid generated by reading a table. For each row of this table I read from others to complete data. Application almost always works, but sometimes rows aren't loaded and I receive the message: java.sql.SQLException: ResultSet is closed I'm using SQLServer. Tell me if anyone knows the problem

    This is my code in JSP page


    try { DataTap source = DataTapFactory.getDataSourceAccessor (dbType, url, username, password, driverName); Collection detail= source.getPBSDetail((String)request.getSession().getAttribute("PBSNAME")); Iterator iter = detail.iterator(); rowsFetched=detail.size(); request.getSession().setAttribute("ROWS",""+rowsFetched); String data[][] = new String[detail.size()+1][ini.colPBS()+10]; int row=0; for (int k=0;k<=12;k++) {Totali[k]=0;} while(iter.hasNext()){ PBSDetail d = (PBSDetail)iter.next(); ............ try { DataTap sourceEndexm = DataTapFactory.getDataSourceAccessor (dbType, url, username, password, driverName); if (end==11) {qualify="JR";} if (end==12) {qualify="SR";} if (end==13) {qualify="MG";} Collection endexm= sourceEndexm.getEndEstimation((String)request.getSession().getAttribute("PBSNAME"), d.getlev1(),d.getlev2(),d.getlev3(),d.getlev4(),qualify); Iterator iterEndexm = endexm.iterator(); while(iterEndexm.hasNext()){ EndEstimation ee = (EndEstimation)iterEndexm.next(); data[row][end]= String.valueOf(ee.getEndexm()); if (data[row][end].equals(null)) {data[row][end]="0.0";} }} catch (Exception e){ e.printStackTrace(); } } .......... catch (Exception e){ e.printStackTrace(); } instead here below one of methods I call from JSP page in my DataAccessObject: ............ public Collection getPBSDetail(String PBS) { Collection results = new ArrayList(); final String GET_PBSDETAIL = "Select * from PBSDTTBL WHERE PBS='" + PBS + "'" + " ORDER BY NOMELEV1,NOMELEV2,NOMELEV3,NOMELEV4"; Connection con = _connectionPool.getConnection(); try { stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(GET_PBSDETAIL); System.out.println(GET_PBSDETAIL); while (rs.next()) { PBSDetail detail = new PBSDetail(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), Double.parseDouble(rs.getString(6)), Double.parseDouble(rs.getString(7)), Double.parseDouble(rs.getString(8))); results.add(detail); } stmt.close(); _connectionPool.closeConnection(con); con.close(); } catch (SQLException ex) { System.out.println(ex); } finally { try { stmt.close(); con.close(); } catch (SQLException ex2) { System.out.println(ex2); } } return results; }
    ...............
    (I have of course a PBSDetail class) Do you think that's OK to do so? Thanks bye
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    Nobody's going to trawl through that code as you've posted it. Please repost it using the [code] tags.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    15
    Rep Power
    0
    Sorry.........

    try
    {
    DataTap source = DataTapFactory.getDataSourceAccessor
    (dbType, url, username, password, driverName);
    Collection detail= source.getPBSDetail((String)request.getSession().getAttribute("PBSNAME"));
    Iterator iter = detail.iterator();
    rowsFetched=detail.size();
    request.getSession().setAttribute("ROWS",""+rowsFetched);
    String data[][] = new String[detail.size()+1][ini.colPBS()+10];
    int row=0;
    for (int k=0;k<=12;k++) {Totali[k]=0;}
    while(iter.hasNext()){
    PBSDetail d = (PBSDetail)iter.next();

    ............

    try {
    DataTap sourceEndexm = DataTapFactory.getDataSourceAccessor
    (dbType, url, username, password, driverName);
    if (end==11) {qualify="JR";}
    if (end==12) {qualify="SR";}
    if (end==13) {qualify="MG";}
    Collection endexm=
    sourceEndexm.getEndEstimation((String)request.getSession().getAttribute("PBSNAME"),
    d.getlev1(),d.getlev2(),d.getlev3(),d.getlev4(),qualify);
    Iterator iterEndexm = endexm.iterator();
    while(iterEndexm.hasNext()){
    EndEstimation ee = (EndEstimation)iterEndexm.next();
    data[row][end]= String.valueOf(ee.getEndexm());
    if (data[row][end].equals(null)) {data[row][end]="0.0";}
    }}

    catch (Exception e){
    e.printStackTrace();
    }
    }

    ..........

    catch (Exception e){
    e.printStackTrace();
    }



    instead here below one of methods I call from JSP page in my DataAccessObject:

    ............
    public Collection getPBSDetail(String PBS) {
    Collection results = new ArrayList();
    final String GET_PBSDETAIL = "Select * from PBSDTTBL WHERE PBS='" + PBS +
    "'" +
    " ORDER BY NOMELEV1,NOMELEV2,NOMELEV3,NOMELEV4";
    Connection con = _connectionPool.getConnection();
    try {
    stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(GET_PBSDETAIL);
    System.out.println(GET_PBSDETAIL);
    while (rs.next()) {
    PBSDetail detail = new PBSDetail(rs.getString(1), rs.getString(2),
    rs.getString(3), rs.getString(4),
    rs.getString(5),
    Double.parseDouble(rs.getString(6)),
    Double.parseDouble(rs.getString(7)),
    Double.parseDouble(rs.getString(8)));
    results.add(detail);

    }
    stmt.close();
    _connectionPool.closeConnection(con);
    con.close();
    }
    catch (SQLException ex) {
    System.out.println(ex);
    }
    finally {
    try {
    stmt.close();
    con.close();
    }
    catch (SQLException ex2) {
    System.out.println(ex2);
    }
    }
    return results;
    }
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    17
    Rep Power
    0
    try {
    stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(GET_PBSDETAIL);
    System.out.println(GET_PBSDETAIL);
    while (rs.next()) {
    PBSDetail detail = new PBSDetail(rs.getString(1), rs.getString(2),
    rs.getString(3), rs.getString(4),
    rs.getString(5),
    Double.parseDouble(rs.getString(6)),
    Double.parseDouble(rs.getString(7)),
    Double.parseDouble(rs.getString(8)));
    results.add(detail);

    }
    stmt.close();
    _connectionPool.closeConnection(con);
    con.close();

    after the try why did u close the connection.either include these 3 statements inside the try.
    when this code is executed...after "try" is done, the connection is closed and so you are receiving that error.

IMN logo majestic logo threadwatch logo seochat tools logo