gpt4 book ai didi

java - 是否有 Db2 标量函数来检索给定 SQLCODE 的完整错误消息信息?

转载 作者:行者123 更新时间:2023-12-02 11:12:34 25 4
gpt4 key购买 nike

如果我有 SQL 错误代码,我想知道是否有任何现有解决方案可以在代码中获取详细的数据库错误解释。我想将此信息转储到日志中,这样我就不必每次遇到一个人时都查找谷歌。

目标转速堆栈是 - Java、DB2。

谢谢!

最佳答案

函数SYSPROC.SQLERRM将返回给定SQLCODE的错误消息。 https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.sql.rtn.doc/doc/r0022027.html

例如这将返回 SQLCODE 100 的短消息(即 SQL100W)

VALUES (SYSPROC.SQLERRM (100))

像这样

1
---------------------------------------------------------------------------------------------------
SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a query is an empty table.

1 record(s) selected.

这将返回完整的消息

VALUES (SYSPROC.SQLERRM ('SQL100W', '', '', 'en_US', 0))

将返回

1                                                                                                                                                                                                                  
----------------------------------------------------------------------------

SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of
a query is an empty table.

Explanation:

One of the following conditions is true:

* No row was found that meets the search conditions specified in an
UPDATE or DELETE statement.

* The result of a SELECT statement was an empty table.

* A FETCH statement was executed when the cursor was positioned after
the last row of the result table.

* The result of the SELECT used in an INSERT statement is empty.

No data was retrieved, updated, or deleted.

User response:

No action is required. Processing can continue.

sqlcode: +100

sqlstate: 02000



1 record(s) selected.

关于java - 是否有 Db2 标量函数来检索给定 SQLCODE 的完整错误消息信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50520431/

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