最近发现如果狂刷一个页面就会导致数据库连接数一直增长,
按理说使用了数据库连接池,而且确保页面使用完连接之后关闭连接,
应该是使用连接池的连接,不会去生成新的连接了,可是这种现象让我
百思不得奇解啊,还望高手赐教!
数据库用的是oracle 页面是jsp的

解决方案 »

  1.   

    会不会是这样,你还没调用close方法的时候就又刷新了啊
      

  2.   

    你肯定没把连接砌底关掉,给你一个例子:%
    Connection conn2=null;
    Statement stmt2=null;
    ResultSet rs2=null;
    String sql2="";try
     {
                
         conn2=sfca.common.ConnectionManager.getConnection();
         stmt2=conn2.createStatement();
         rs2=stmt2.executeQuery(sql2);
        
         while(rs2.next())
         {
    %>                 
    <%   
         }
    }
    catch(Exception e)
    {
       e.printStackTrace();
    }    
    finally
    {   
       if(rs2!=null)
       {
         rs2.close();
         rs2=null;
       }
       
       if(stmt2!=null)
       {
          stmt2.close();
          stmt2=null;
       }  
       if(conn2!=null)
       {
          conn2.close();
          conn2=null;
       }
    }         
        
    %>      
      

  3.   

    你的close不要写在finally里面,写在主要的程序段里面吧
      

  4.   

    infowain(infowain)还是翻番java书去吧。
      

  5.   

    Connection conn = null;
    ResultSet Rst=null;
    Statement smt=null;
    DBC MYDB=new DBC("mssql");
    conn=MYDB.getcon();
    if(conn!=null){
    smt=conn.createStatement();
    }else{
    return;
    }
    Connection conn1 = null;
    ResultSet Rst1=null;
    Statement smt1=null;
    DBC MYDB1=new DBC("mssql");
    conn1=MYDB1.getcon();
    if(conn1!=null){
    smt1=conn1.createStatement();
    }else{
    return;
    }Connection con = null;
    ResultSet sqlRst=null;
    Statement stmt=null;
    DBC DB=new DBC("mssql");
    con=DB.getcon();
    if(con!=null){
    stmt=con.createStatement();
    }else{
    return;
    }       Rst=smt.executeQuery(sql);
           while(Rst.next())
            {
              o=Rst.getInt("openyear");    
                 .........
                 ..........     查询
            }
    释放数据库
    try{Rst.close();}catch(Exception e){}
    try{smt.close();}catch(Exception e){}
    try{MYDB.free("mssql",conn);}catch(Exception e){}try{Rst1.close();}catch(Exception e){}
    try{smt1.close();}catch(Exception e){}
    try{MYDB1.free("mssql",conn1);}catch(Exception e){}try{sqlRst.close();}catch(Exception e){}
    try{stmt.close();}catch(Exception e){}
    try{DB.free("mssql",con);}catch(Exception e){}这样是没有问题的吧,每次都释放了数据库连接了,可是如果狂刷一个页面就不停生成新连接,是什么原因?
      

  6.   

    可是每个页面都有代码啊
    释放数据库
    try{Rst.close();}catch(Exception e){}
    try{smt.close();}catch(Exception e){}
    try{MYDB.free("mssql",conn);}catch(Exception e){}try{Rst1.close();}catch(Exception e){}
    try{smt1.close();}catch(Exception e){}
    try{MYDB1.free("mssql",conn1);}catch(Exception e){}try{sqlRst.close();}catch(Exception e){}
    try{stmt.close();}catch(Exception e){}
    try{DB.free("mssql",con);}catch(Exception e){}刷得慢就没事,刷得快就一直生成新连接
      

  7.   

    把connection 的关闭写在finally{ try{ if(connection!=null) connection.close()} catch{}}块中
      

  8.   

    试过了放在finally{}里面,还是不行,