[在DB2批处理更新中执行更新查询时获取错误。
例外:
org.springframework.dao.DataAccessResourceFailureException: PreparedStatementCallback; SQL [UPDATE DBO.STG_BILLPAY_INV_BT SET INV_SENT_FLG = ?, MDY_TS = ?, MDY_USR = ? WHERE INV_PDF_NM = ?]; [jcc][t4][2027][11212][3.53.70] A connection failed but has been re-established. The host name or IP address is "10.1.1.1" and the service name or port number is 446.
Special registers may or may not be re-attempted (Reason code = 2). ERRORCODE=-4498, SQLSTATE=08506; nested exception is com.ibm.db2.jcc.b.ClientRerouteException: [jcc][t4][2027][11212][3.53.70] A connection failed but has been re-established. The host name or IP address is "10.1.1.1" and the service name or port number is 446.
Special registers may or may not be re-attempted (Reason code = 2). ERRORCODE=-4498, SQLSTATE=08506
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:105)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:82)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:82)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:655)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:668)
at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:956)
at com.comdata.batch.billtrust.dao.jdbc.ThinBillFileDaoJdbc.updateThinBillFile(ThinBillFileDaoJdbc.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy12.updateThinBillFile(Unknown Source)
at com.comdata.batch.billtrust.service.impl.ThinBillFileServiceImpl.getStagingThinBillData(ThinBillFileServiceImpl.java:297)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy15.getStagingThinBillData(Unknown Source)
at com.comdata.batch.billtrust.MainBatch.executeThinBilFileProcess(MainBatch.java:37)
at com.comdata.batch.billtrust.MainBatch.main(MainBatch.java:51)
Caused by: com.ibm.db2.jcc.b.ClientRerouteException: [jcc][t4][2027][11212][3.53.70] A connection failed but has been re-established. The host name or IP address is "10.1.1.1" and the service name or port number is 446.
Special registers may or may not be re-attempted (Reason code = 2). ERRORCODE=-4498, SQLSTATE=08506
at com.ibm.db2.jcc.b.bd.a(bd.java:304)
at com.ibm.db2.jcc.b.bd.a(bd.java:356)
at com.ibm.db2.jcc.t4.a.a(a.java:380)
at com.ibm.db2.jcc.t4.a.I(a.java:811)
at com.ibm.db2.jcc.t4.a.a(a.java:716)
at com.ibm.db2.jcc.t4.bb.T(bb.java:1240)
at com.ibm.db2.jcc.t4.bb.A(bb.java:610)
at com.ibm.db2.jcc.t4.db.o(db.java:771)
at com.ibm.db2.jcc.t4.db.g(db.java:141)
at com.ibm.db2.jcc.t4.db.a(db.java:38)
at com.ibm.db2.jcc.t4.t.a(t.java:32)
at com.ibm.db2.jcc.t4.sb.h(sb.java:141)
at com.ibm.db2.jcc.b.fm.bb(fm.java:1923)
at com.ibm.db2.jcc.b.gm.dc(gm.java:2551)
at com.ibm.db2.jcc.b.gm.q(gm.java:2678)
at com.ibm.db2.jcc.b.gm.Ub(gm.java:1966)
at com.ibm.db2.jcc.b.gm.addBatch(gm.java:1917)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.addBatch(NewProxyPreparedStatement.java:131)
at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:970)
at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:956)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:639)
... 32 more
XML配置:具有c3p0配置的Spring JDBC模板。
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="user" value="${billtrust.db.username}" />
<property name="password" value="${billtrust.db.password}" />
<property name="driverClass" value="${billtrust.db.driverClassName}" />
<property name="jdbcUrl" value="${billtrust.db.url}" />
<property name="initialPoolSize" value="1" />
<property name="maxPoolSize" value="10" />
<property name="minPoolSize" value="1" />
<property name="acquireIncrement" value="1" />
<property name="maxIdleTimeExcessConnections" value="300" />
<!-- maxConnectionAge: connection lifetime seconds -->
<property name="maxConnectionAge" value="7200" />
<!-- acquireRetryAttempts is how many times connect is retried before giving
up, 0 = infinite, should be 1 in unit tests -->
<property name="acquireRetryAttempts" value="30" />
<!-- acquireRetryDelay is how many wait time in ms between reconnect attempts -->
<property name="acquireRetryDelay" value="1000" />
<!-- checkoutTimeout: nbr of millis request will wait for a pooled connection
when maxed out -->
<property name="checkoutTimeout" value="60000" />
</bean>
示例代码:使用BatchPreparedStatementSetter的jdbc模板进行批量更新。BatchPreparedStatementSetter prepareStatementSetter =新的BatchPreparedStatementSetter(){
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Calendar calendar = Calendar.getInstance();
java.sql.Timestamp ourJavaTimestampObject = new java.sql.Timestamp(calendar.getTime().getTime());
ps.setString(1, option);
ps.setTimestamp(2, ourJavaTimestampObject);
ps.setString(3, "JAVA");
ps.setString(4, thinBillFileUpdate.get(i));
}
@Override
public int getBatchSize() {
return thinBillFileUpdate.size();
}
};
int[] batchUpdate = this.getJdbcTemplate().batchUpdate(updateThinBillStagingTable, preparedStatementSetter);
Should get update the Database(DB2) successfully.
关键错误消息将是:
由:com.ibm.db2.jcc.b引起。ClientRerouteException:[jcc] [t4] [2027] [11212] [3.53.70]连接失败,但已重新建立。主机名或IP地址为“ 10.1.1.1”,服务名或端口号为446。特殊寄存器可能会也可能不会被尝试(原因代码= 2)。 ERRORCODE = -4498,SQLSTATE = 08506
这里是关于-4498的解释:
IBM数据服务器驱动程序针对JDBC和SQLJ发出的错误代码https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.5.0/com.ibm.db2.luw.apdv.java.doc/src/tpc/imjcc_rjvjcsqc.html摘下
-4498消息文本:连接失败,但已重新建立。如果需要,可以重播特殊的寄存器设置。连接的主机名或IP地址:主机名。连接的服务名称或端口号:服务名称。原因码:原因码。失败代码:失败代码。错误代码:错误代码。说明:连接已重新建立。在某些情况下,直到下次使用时才建立与服务器的网络连接或传输。重新建立连接后,所有会话资源均设置为其初始默认值。该应用程序将回滚到上一个提交点。原因码指示将哪些特殊寄存器值应用于新连接。原因码的可能值为:
这里是-4498和ClientRerouteException的很好的参考之一:
为MobileFirst Server和Application Center数据源配置DB2 HADR无缝故障转移https://www.ibm.com/support/knowledgecenter/SSHS8R_7.0.0/com.ibm.worklight.installconfig.doc/install_config/c_config_db2_hadr_seamless_failover.html
snipped
对于DB2 HADR,缺省情况下,当DB2 JDBC驱动程序在第一次尝试重用现有连接期间检测到数据库故障转移后,执行客户机重新路由时,该驱动程序将触发com.ibm.db2.jcc.am。ClientRerouteException ,带有ERRORCODE = -4498和SQLSTATE = 08506。
因此,当数据库故障转移时,它可能会记录在Db2 HADR环境中。
希望这会有所帮助。