Re: Memory leak ?

Поиск
Список
Период
Сортировка
От Lew
Тема Re: Memory leak ?
Дата
Msg-id inipq8$o3h$1@news.albasani.net
обсуждение исходный текст
Ответ на Re: Memory leak ?  (Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>)
Список pgsql-jdbc
Mikko Tiihonen wrote:
> Pierre Le Mouëllic wrote:
>> With this code :
>>
>> public class TestJDBC {
>>
>>      private static Timer timer;
>>
>>      private static Connection connDB;
>>      private static PreparedStatement sQLStatement;
>>
>>      public static void main(String[] args) throws SQLException, ClassNotFoundException {
>>
>>          connexion("jdbc:postgresql://praslin.qual.dc1:5432/G01DPM","postgres8","password");
>>
>>          timer = new Timer();
>>          timer.schedule(new local_task(), 1000L, 1000);
>>      }
>>
>>      static class local_task extends TimerTask {
>>
>>          public void run() {
>>              ResultSet rs=null;
>>              try {
>>                  sQLStatement.setInt(1, 2602);
>>                  rs = sQLStatement.executeQuery();

> Missing
> rs.close();

Not needed.

 From <http://download.oracle.com/javase/6/docs/api/java/sql/ResultSet.html>:

"A ResultSet object is automatically closed when the Statement object that
generated it is closed, re-executed, or used to retrieve the next result from
a sequence of multiple results."


>>                  sQLStatement.setInt(1, 2604);
>>                  rs = sQLStatement.executeQuery();

> Missing
> rs.close();

Nope.

In fact, it's rather an antipattern to call 'ResultSet#close()' explicitly.

>>                  sQLStatement.setInt(1, 2605);
>>                  rs = sQLStatement.executeQuery();
>>              } catch (SQLException e) {
>>              }
>>              finally{
>>
>>                  try {
>>                      if(rs!=null)
>>                          rs.close();

What's bizarre here is that we aren't closing the statement.

That's weird.

>>                  } catch (SQLException e) {
>>                  }
>>
>>                  rollBack();
>>              }
>>          }
>>      }

--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Lew
Дата:
Сообщение: Re: Memory leak ?
Следующее
От: Craig Ringer
Дата:
Сообщение: Re: Recommended resource type and settings for J2EE/Glassfish connection pool