开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜