I am trying to use prepared statements which operate on a database located quite far away, there is considerable lag and unreliability involved in the network connection used to access this database. Downtimes of up to a minute are common. The problem is that in case of such a failure, if my program tries to execute any prepared statement, the whole thread goes into infinite wait. It never times out and just remains stuck, waiting for a response from the database.
I execute the prepared statement by using the executeQuery() method, but if the network fails before this statement is reached, then the whole system hangs and goes into indefinite wait, i have looked into options like the setQueryTimeout() but it seems that this doesn't work for network failures, I briefly looked into transaction managers but it seems that using a Transaction Manager just to be able to introduce a timeout is an Overkill.
Is there any way around this problem ?