views:

363

answers:

1

How do I cancel a long running postgres query via JDBC or Java?

The usecase would be that an user starts a query on a postgres database via a front end, but then he decides otherwise and wants to abort/cancel the currently running query.

+1  A: 

Call java.sql.PreparedStatement.cancel() method. Check whether postgres JDBC driver supports this method. As far as I can see from the source code of the latest postgres JDBC driver it does stop the query.

Boris Pavlović
Thanks Boris, thats it. Works like a charm.
Dieter