Preetom Saha Arko
Preetom Saha Arko

Reputation: 2748

How to use transaction in oracle database from java back end?

I have to insert some information to my oracle database. Some of them are complex (array of arrays), so I can't pass them to a PL/SQL function. All the data can't be inserted using one query, and I have to insert data to multiple tables too. But if insertion fails once for a table, the whole insertion process should be rolled back. So I need to use transaction.

I am using java code and PreparedStatement, ResultSet, CallableStatement and other related things to perform database operations from my java back end. How can I define and use transactions from this java back end? Basically I am using Spring MVC.

N.B. No Hibernate related solution please.

Upvotes: 1

Views: 1379

Answers (2)

Ori Marko
Ori Marko

Reputation: 58822

If you are not using java 8 see oracle full explanation

Upvotes: 1

Usagi Miyamoto
Usagi Miyamoto

Reputation: 6329

Use Connection.setAutoComit(false) just after obtaining the Connection instance.

This will make your connection a non auto-commit transaction.

See: http://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#setAutoCommit-boolean-

Upvotes: 3

Related Questions