Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set lock time out in jdbc

Tags:

jdbc

is there a way to set the lock timeout in jdbc? It should work for PostgreSQL, Oracle, SQL Server and MySQL.

I found the method setQueryTimout in the statement class. Is this the right thing? Or is this a general timeout, so when a long update takes longer than the query timout, does an exception occur? Even if the query does not wait for a lock?

What is the best way the set lock timeout in jdbc?

like image 554
Peter Avatar asked Jan 31 '26 11:01

Peter


1 Answers

There is no standard JDBC option to configure a lock timeout. This is database specific and not supported by the JDBC standard. You will need to find out how each database supports lock timeout and how this is configured in their driver, and then handle the differences between each driver.

The query timeout is not a lock timeout. It specifies the time a query is allowed to run (if supported by the driver and database), this is intended to kill/prevent long-running queries.

like image 135
Mark Rotteveel Avatar answered Feb 03 '26 10:02

Mark Rotteveel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!