Amit Maniar
Amit Maniar

Reputation: 1196

How to set timeout for INSERT query in postgres with MyBatis (Java)

In Mybatis there is an attribute timeout for mapper files but that throws Exception.

Cause: org.postgresql.util.PSQLException: Method org.postgresql.jdbc4.Jdbc4PreparedStatement.setQueryTimeout(int) is not yet implemented.
uncategorized SQLException for SQL []; SQL state [0A000]; error code [0]; Method org.postgresql.jdbc4.Jdbc4PreparedStatement.setQueryTimeout(int) is not yet implemented.; nested exception is org.postgresql.util.PSQLException: Method org.postgresql.jdbc4.Jdbc4PreparedStatement.setQueryTimeout(int) is not yet implemented.
........

Upvotes: 0

Views: 2543

Answers (1)

Craig Ringer
Craig Ringer

Reputation: 324475

PostgreSQL doesn't currently support query timeouts at the server level. So PgJDBC has a hard time implementing them client-side, though I rather thought current PgJDBC versions emulated it using statement_timeout.

Anyway, if updating to the latest PgJDBC (you failed to specify your version) doesn't help, what you need to do is SET statement_timeout before your query, then reset it after the query. Just execute:

SET statement_timeout = '5s';

or whatever before your query. If you're running it within an already open transaction you can use SET LOCAL to make the setting transaction scoped.

Upvotes: 1

Related Questions