开发者

continue insert when exception is raised in postgres

开发者 https://www.devze.com 2023-01-03 07:11 出处:网络
HI, Iam trying to insert batch of records at a time when any of the record fails to insert i need to trap that record and log that to my failed record maintanance table and then the insert should co

HI,

Iam trying to insert batch of records at a time when any of the record fails to insert i need to trap that record and log that to my failed record maintanance table and then the insert should continue. Ki开发者_开发百科ndly help on how to do this.


If using a Spring or EJB container there is a simple trick which works very well : provide a LogService witn a logWarning(String message) method. The method must be annotated/configured with the REQUIRES_NEW transaction setting.

If not then you'll have to simulate it using API calls. Open a different connection for the logging, when you enter the method begin the transaction, before leaving commit the transaction.

When not using transactions for the insert, there is actually nothing special you need to do, as by default most database run in autocommit and commit after every statement.

0

精彩评论

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

关注公众号