【问题标题】:how to check which column cause db2 22001 error?如何检查哪一列导致 db2 22001 错误?
【发布时间】:2015-09-11 11:42:59
【问题描述】:

早安,

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 由字符数据引起,发生右截断;例如,更新或插入值是对于列而言太长的字符串,或者由于太小而无法将日期时间值分配给宿主变量。

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

【问题讨论】:

    标签: sql db2 sqlcode


    【解决方案1】:

    此错误消息无法确定导致问题的列。但基于此错误: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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-01
      • 1970-01-01
      • 2021-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-19
      • 2011-02-02
      相关资源
      最近更新 更多