Indicator overflow

Connection conn = null;
PrepareStatement ps = null;
ResultSet rs = null;
String sql = "select * from  ...  where  id =? ";

try{

    conn = forName("jdbc.***");
        for(**;**;**){
           //notice : there is a "ps=conn.prepaeStatement" in loop
            ps= conn.prepareStatement(sql);
            ps.setString(1,"4");
            rs=ps.executeQuery();
             while(rs.next()){
                  ......    
               }
         }

}catch(Exception e){


}finally{

close(conn,ps,rs);
}

      

   cough! cough! In the loop ps=conn.prepareStatement(), there is no close ps at the end of the loop, then a ps will be created again each time the loop, corresponding to a Cursor will be opened in "in DB", and the ps will be executed in the loop. There is no ps.close() after executeQuery().

 

   I thought about it with my thighs, I only have one ps variable! Even if ps=conn.preapareStatement() is executed every time the loop is executed, isn't this just reassignment! The former ps object has no reference to it! Then won't it be collected by GC ashes!

 

    too younge too simple sometimes navie , every time the object of ps is created, a Cursor is opened in "DB". Is it a special GC pot! GG must have killed the former ps (crying, crying is useless), how can it kill the Cursor opened in DB! (Nima, it seems that the long legs still have no brains to use)

 

Director: All departments are ready, action!!!! 

java shouts to oracle/mysql: you guys compare, put so many Cursor out, why don't you care about it!

oracle: "blame me"!

mysql: "blame me"!

 

java:...... 

Don't forget to copy when you study >> http://my.oschina.net/zenglingfan/blog/62746

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326694049&siteId=291194637