查询完一次即关闭相应ResultSet
加上
rs.close();

解决方案 »

  1.   

    while(rs.next()){
       //对rs的处理语句
    }
    if(rs != null) rs.close();上面语句需要放到try语句中
      

  2.   

    请高手给看一下: 说明:strThreeTemp中存放一个字符串,由三个字符的代码组成,strThree从中截取三个字符的代码,从city_code表中查询对应的四个字符的代码到第四次查询的时候,抛出违例“java.sql.SQLException: 用尽的 Resultset”查询的是oracle数据库,同样的代码,查询SQL Server数据库时就没有问题。
    try{
         Class.forName("oracle.jdbc.driver.OracleDriver");
         Connection con=DriverManager.getConnection("","","");
         Statement stat=con.createStatement();    for(int j=0;j<CHNletters;j++)
       {
          strThree=strThreeTemp.substring(3*j,3*j+3);
                strSQLFour="SELECT DISTINCT code_C4 "+
                     "FROM city_code "+
                     "WHERE code_C3 LIKE '%"+strThree+"%'";
          try{        rs=stat.executeQuery(strSQLFour);        rs.next();
            str=rs.getString("code_C4").trim();
            if(rs!=null)rs.close();      }catch(Exception e){
            System.out.println(e.toString());
          }    }
       }catch(Exception e)
       {
          System.out.println(e.toString());
       }
      

  3.   

    try{        rs=stat.executeQuery(strSQLFour);        rs.next();
            str=rs.getString("code_C4").trim();
            if(rs!=null)rs.close();      }catch(Exception e){
            System.out.println(e.toString());
          }
    >>
    try{        rs=stat.executeQuery(strSQLFour);        rs.next();
            str=rs.getString("code_C4").trim();
          }catch(SQLException e){ 
            System.out.println(e.toString());
          } finally {   
           try{ if(rs!=null)rs.close(); } catch (Exception e) { }
    }
      

  4.   

    那是因为你没有close statement,rs.close之后关闭stat
      

  5.   

    多谢 Rain999 ,可还是不行啊…… :(
      

  6.   

    多谢ChDw,试过关闭stat,第二次查询时抛出违例:"java.sql.SQLException: 关闭的语句"
    若在循环内定义stat,同样抛出违例“java.sql.SQLException: 用尽的 Resultset”而且,访问SQL Server的数据库就不会出现这个问题。
      

  7.   

    你这样子
    try{        rs=stat.executeQuery(strSQLFour);        rs.next();
            str=rs.getString("code_C4").trim();
            if(rs!=null)rs.close();      }catch(Exception e){
            System.out.println(e.toString());
          }
    >>
    try{        rs=stat.executeQuery(strSQLFour);        rs.next();
            str=rs.getString("code_C4").trim();
          }catch(SQLException e){ 
            System.out.println(e.toString());
          } finally {   
           try{ if(rs!=null)rs.close(); } catch (Exception e) { }
           try{ if(stat!=null)stat.close(); } catch (Exception e) { }
          }一个rs和stat都不应该调用两次close
      

  8.   

    不明白上面说的是什么意思!
    rs=stat.executeQuery(strSQLFour);
    是一个新的rs,再用rs.close();并不是调用两次close()!你的数据库连接也没有关,stat也没有关,很容易把资源占光,然后出错!
    把你的数据库重启一下,释放掉没用的链接,并在程序最后把stat和con都close
      

  9.   

    数据库是生产数据库,不可能重启
    把所有的stat、con、rs都close,仍然无效。:(
      

  10.   

    try{
            rs=stat.executeQuery(strSQLFour);    ===>while(rs.next()){
              str=rs.getString("code_C4").trim();
            }
            
            rs.close();      }catch(Exception e){
            System.out.println(e.toString());
          }
    试试吧
      

  11.   

    试试这样:for(...)
    {
        Statement stat=con.createStatement();
        ......
        rs=stat.executeQuery(strSQLFour);
        if(rs.next())
        {
            ......
        }
        rs.close();
        if(stat != null)
        {
            stat.close();
        }
    }