如题,不知谁能提供一个Connection Leak的例子,多谢!

解决方案 »

  1.   

    已经解决了,谢谢帮忙!
    写个方法:
    public Connection getConnection()
    {   
    try   
        {

    javax.naming.Context ctx = new InitialContext();   
    ds = (DataSource)ctx.lookup("data");//oracleserver这个是在weblogic里面配置的JNDI   Name:名称。   
    con = ds.getConnection();   
    ctx.close();   
        }   
        catch(Exception e)   
        {   
         e.printStackTrace();   
        }   
        finally   
        {   
            ds = null;   
        }   
        return con;   
    }   在servlet中调用
    Leak leak = new Leak();
     java.sql.Connection  conn = null;   
          java.sql.Statement  stmt = null;   
          //java.sql.PreparedStatement   pstmt = null;   
          java.sql.ResultSet   rs =   null;   
        
          Connection con = leak.getConnection();   
          conn = leak.getConnection();   //此处不关闭 
          try {
    stmt = con.createStatement();
    String sql = "select * from message";
                System.out.println("message....");
                rs = stmt.executeQuery(sql);
                while(rs.next())
                {
                 System.out.println("数据 : " + rs.getString(2));
                }
    } catch (SQLException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }   
          try   
          {
           con.close();
            rs.close();

    con=null;
          }   
          catch(Exception   e)   
          {
         e.printStackTrace();
          }    
    }