Subject lock table/record with JDBC to prevent deadlock
Author firebirdyah
Hello,

I would like to access one database from different Java programs. I
am using JDBC. See the following simple scenario, program A and B
(they need to do a lot more in the transaction):

A: auto commit is set to false (implicit transaction start)
A: update table XYZ
B: auto commit is set to false (implicit transaction start)
B: update table XYZ: this actions is hold until A commits
A: commit
B: an exception is generated on the update:
interbase.interclient.DeadlockException: [interclient][interbase]
deadlock.

I need to prevent the deadlock exception. Using isql, I can do this
by reserving a table by staring a transaction: "set transaction read
write wait reserving XYZ for protected write;", no deadlock occurs,
the 'B' programs wait as required.

This can not be done in JDBC, while it (as far as I can see) starts a
transaction automatically. When I try con.commit(); statement.execute
("set transaction"); I get the exception [interclient][interbase]
invalid transaction handle (expecting explicit transaction start).

My question is: how can I update the same table from different Java
programs without getting an deadlock exception?

Where can I find more info about the possible SQL-statements I can do
in JDBC? Examples?

Kind regards, Yvon