开发者

JDBC check if a connection can warantee it will commit without errors

开发者 https://www.devze.com 2023-02-22 03:52 出处:网络
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 co开发者_StackOverflowmmit.

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 co开发者_StackOverflowmmit.

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.


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.


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");
0

精彩评论

暂无评论...
验证码 换一张
取 消