且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

向数据库添加唯一值

更新时间:2021-08-07 22:34:31

i建议您采用方法 1 ,但不要直接抛出异常.请在对其进行检查之前,先检查它是否与唯一键相关,并显示一条正确的消息,指出名称已存在于数据库."
i will suggest you to go with approach 1 but do not throw the exception as it is.Check it before like if it''s related to unique key display a proper message saying "Name already exists in the database."


在添加之前检查所有项目将是一项开销.我建议你选择第一名.只需确保正确处理异常,以使用户在看到技术错误时不会惊慌失措. :)
Checking all the items before adding will be an overhead. I suggest you go with #1. Just make sure to handle exceptions properly so users will not freak out when they see technical errors. :)