java - How to run SQL TRANSACTION in a PreparedStatement -


i have sql transaction query unable run. can 1 tell me please why? have failed run using preparedstament.executequery(); well.

start transaction; select total_installment_remaining  payment_loan loan_id = 1 update; update payment_loan set total_installment_remaining =total_installment_remaining-1 loan_id = 1; commit; 

turn off autocommit, use connection.commit() end transaction.

connection.setautocommit(false); statement stmt = con2.createstatement();  // automatically start transaction resultset rs = stmt.executequery("select total_installment_remaining  payment_loan loan_id = 1 update");  // process result if needed ...  stmt.executeupdate("update payment_loan set total_installment_remaining =total_installment_remaining-1 loan_id = 1");  // end transaction , persist changes connection.commit(); 

if don't need result of select in code, don't need select ... update in first place, because update lock row anyway.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -