[JDBC] Statement is still active at the back-end even after closing - Mailing list pgsql-jdbc

From Syam Pillai
Subject [JDBC] Statement is still active at the back-end even after closing
Date
Msg-id CAD-KuVN=Q8HTQaBrR850c7JoT6Qfq_OtvMYqtp2utgVxKr9-nA@mail.gmail.com
Whole thread Raw
Responses Re: [JDBC] Statement is still active at the back-end even after closing  (Dave Cramer <pg@fastcrypt.com>)
Re: [JDBC] Statement is still active at the back-end even after closing  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: Statement is still active at the back-end even after closing  (Dave Cramer <pg@fastcrypt.com>)
Re: Statement is still active at the back-end even after closing  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-jdbc
​Not sure if this was reported earlier.

I am using PostgreSQL 9.5.8 and JDBC driver 42.1.4

If I execute the following statements and at Position #1, if I check the pg_stat_activity from another connection (let's say from the psql application), I can see that the 'Statement s' is still active:

try {
Class.forName("org.postgresql.Driver");
Connection connection = null;
connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/cadup","user", "password");
Statement s = connection.createStatement();
ResultSet rs =s.executeQuery("SELECT 1 FROM core.Person");
if(rs.next()) {
System.err.println("Yes, we got a row!");
} else {
System.err.println("No rows found");
}
s.close();
Thread.sleep(10000); // Position #1
connection.close();
} catch(Exception e) {
e.printStackTrace();
}


===============
Query executed to check the activity:
SELECT pid, datname, now() - pg_stat_activity.query_start AS duration, state, query
FROM pg_stat_activity
WHERE now() - pg_stat_activity.query_start > interval '1 second';
Output from psql:
  pid  | datname |    duration     | state |           query           
-------+---------+-----------------+-------+---------------------------
 17775 | xxxx   | 00:00:07.481294 | idle  | SELECT 1 FROM core.Person

pgsql-jdbc by date:

Previous
From: Piyush Sharma
Date:
Subject: [JDBC] [pgjdbc/pgjdbc] 29f574: doc: Added quotes to URL in '@see' tag overorg.po...
Next
From: Dave Cramer
Date:
Subject: Re: [JDBC] Statement is still active at the back-end even after closing