mysql unique index used as exception handling method in java
问题 I want to know whether is it a good idea to catch exception based on unique index of sql in java. i want to catch an exception like 'duplicate entry for 1-0' if so then handle exception otherwise insert properly in database table? 回答1: I say you don't do that, for two reasons: the error messages are a bit unclear: ERROR 1062 (23000): Duplicate entry 'xxx' for key 1 . Are you always 100% sure which key is 1? it locks in you to a specific database vendor I find it simpler to transactionally :