gpt4 book ai didi

MySQL 存储过程,永远不会引发错误?

转载 作者:行者123 更新时间:2023-11-29 07:02:27 24 4
gpt4 key购买 nike

我想在 MySQL 中创建一个带有 try/catch 的存储过程,以防止错误进入我的 java 项目。但是由于 MySQL 中没有 try/catch,我正在寻找替代方案。

我唯一需要防止的是不要在我的 java 项目中从 mysql 中得到“重复键”错误。如果我收到此错误,我不想显示任何内容并表现得就像它已正常插入一样。

这可能吗?

最佳答案

为什么不在您的应用程序中捕获此错误?

无论如何,来自文档:http://dev.mysql.com/doc/refman/5.5/en/insert.html

If you use the IGNORE keyword, errors that occur while executing the INSERT statement are treated as warnings instead. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row still is not inserted, but no error is issued

.

关于MySQL 存储过程,永远不会引发错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9403003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com