djechlin
djechlin

Reputation: 60778

Insert into two different tables in one JDBC prepared statement

This command:

INSERT INTO t1 values (d1)
INSERT INTO t2 values (d2)

I want to run in one prepared statement. Logically they should be transactional so wrapped in a block. Is this possible in JDBC which I understand doesn't allow multiple SQL operations per update?

Upvotes: 0

Views: 1613

Answers (1)

Joshua Martell
Joshua Martell

Reputation: 7212

You need to begin a transaction, run both inserts, then commit. Or look into allowMultiQueries=true in your JDBC connection parameters.

Upvotes: 1

Related Questions