sql - 如何检查哪一列导致 db2 22001 错误?

标签 sql db2 sqlcode

再会,

org.springframework.dao.DataIntegrityViolationException: could not insert: [com.entity.payment.BPaymentItem]; SQL [insert into sc.PHistoryItem (amount, beneficiaryAccNo, beneficiaryBankCode, beneficiaryBankName, beneficiaryRef2, billCode, branchId, chargeTo, cibRefNo, cifId, collectionAccountNo, companyId, companyName, createdHostDateTime, currentStatus, customerCategoryCharges, customerCategoryCode, customerCategoryId, customerCategoryName, description, errorCode, errorMessage, fromAccountName, fromAccountNo, fromAccountType, fromFavourite, gst, gstAmount, gstInclusive, gstName, gstRate, gstRefNo, gstTaxCode, hostRefNo, nbpsBillerCode, nbpsBillerName, nbpsReferenceNo, nbpsRrn2, nbpsRtn, nbpsSystemReferenceNo, notifyRetryCount, paymentDate, paymentHistoryId, processDate, promotionCharges, promotionCode, promotionId, promotionName, ref1, ref2, reference, rejectReason, remittanceStatus, remittanceTo, rfi, rrnInfo, rtTrxCode, rtnStatus, serviceCharge, serviceChargeCode, serviceChargeGLAcct, serviceChargeId, serviceChargeName, servicePackageCode, servicePackageId, servicePackageName, serviceType, showTerm, smsCharges, smsGst, smsGstAmount, smsGstInclusive, smsGstRate, smsGstTaxCode, toAccountName, toAccountNo, toAccountType, transferType, type, validateSig, approvalItemId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; nested exception is org.hibernate.exception.DataException: could not insert: [com.entity.payment.BPaymentItem]
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:642) ~[org.springframework.orm-3.0.4.RELEASE.jar:3.0.4.RELEASE]


Caused by: com.ibm.db2.jcc.am.SqlDataException: DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=null, DRIVER=3.63.123
    at com.ibm.db2.jcc.am.fd.a(fd.java:671) ~[db2jcc.jar:na]
...

SQLSTATE 22001 是由字符数据引起的,发生了右截断;例如,更新或插入值是一个对于列来说太长的字符串,或者日期时间值不能分配给主变量,因为它太小了。

但是有没有办法检查导致此错误的列?

最佳答案

无法根据此错误消息确定导致问题的列。但基于此错误:SQLERRMC=null。您的数据试图插入一个空值,要么您的列不接受空值,要么您没有传递正确类型的空值。

如果您使用的是这样的准备好的语句,那么要插入一个空值,您需要指定它。

String query = "insert into table_temp(col1,col2) values(?,?)";
pstmt = con.prepareStatement(query);
pstmt.setString(1, "a");
pstmt.setNull(2, java.sql.Types.NULL);

关于sql - 如何检查哪一列导致 db2 22001 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31040661/

相关文章:

sql - 在 SQL Server 查询结果中显示小计

SQL 从表中选择 - 仅包含特定文件组中的数据

SQL - 如何从 where 子句列表中返回不在表中的 ID?

sql - 如何使用 DB2 限制 DELETE 中的行数?

database - DB2 日志文件限制,SQLCODE : -964

mysql - SQL:按列值分区

sql - 如何在 DB2 中的单个更新语句中更新多个列

java - log4j 2.0 JDBC ConnectionFactory 到 DB2 未将记录添加到日志表 (log4j2.xml)

java - SQL CODE -104(错误)可以代表什么?