views:

666

answers:

3

Unfortunately setTimeout is not implemented for JDBC/postgres. Is there some way I can simulate or workaround this? Functionally I want to execute the query and the then break if it takes longer than N seconds

A: 

One way might be to try running the query in a Timer class. Throw an exception if the Timer ends without a value returned.

Hibernate and JDO supply such a construct. Maybe they'd be good alternatives for you.

duffymo
+3  A: 

The "statement_timeout" looks like what you want.

SET statement_timeout TO 1000; -- for a second
<your_query_here>;
RESET statement_timeout; -- reset
Milen A. Radev
You're better off using RESET statement_timeout; after the query has completed - in case there is a default value...
Magnus Hagander
Fixed now, thanks!
Milen A. Radev
A: 

What if you were to use c3p0 for your dataSource? It has lots of configurable options, and for cranky databases and networks, for example, acquireRetryAttempts, acquireRetryDelay, and breakAfterAcquireFailure.

lumpynose