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