Find if an SQLException was thrown because of a duplicate

前端 未结 9 2632
青春惊慌失措
青春惊慌失措 2021-02-19 11:01

I have a Java program that is agnostic from the database and I need to know, while inserting, if an SQLException was thrown because of a duplicate key.

If I was using a

9条回答
  •  忘了有多久
    2021-02-19 11:41

    I believe a simple and reliable way is to check if the key exists prior to doing the insert. As you have rightly pointed out, each database has it's own way of reporting the error.

提交回复
热议问题