Reputation: 106
Is there a way of checking if a connection will commit without throwing an exception?
I know deferrable foreign key constraints are only enforced at transaction commit.
Does the JDBC (java 6) API provide any method to ask the database whether all operations since the connection began (or last commit) would be successfull?
Regards, Pablo.
Upvotes: 0
Views: 571
Reputation: 7951
If you're using an Oracle database you can check if there are any deferred constraint violations before commit with:
Statement stmt = connection.createStatement();
stmt.executeUpdate("SET CONSTRAINTS ALL IMMEDIATE");
Upvotes: 0
Reputation: 43108
You can't do that. The process of committing takes sometime and in any moment connection can be lost(imagine somebody unplugs the cabel). So no guarantees here. Just catch the exceptions - that why they were invented.
Upvotes: 2