[非原子批处理出现故障]使用 getNextException() 来检索已经过批处理的特定元素的异常。 ERRORCODE=-4228, SQLSTATE=null

[jcc][t4][102][10040][3.57.82] 非原子批处理出现故障。虽然已经提交了批处理,但是该批处理的某个成员至少发生了一个异常。
使用 getNextException() 来检索已经过批处理的特定元素的异常。 ERRORCODE=-4228, SQLSTATE=null

查看db2diag.log日志:
2012-11-20-10.00.33.551000+480 E27658279F1143     LEVEL: Error
PID     : 2276                 TID  : 3796        PROC : db2syscs.exe
INSTANCE: DB2                  NODE : 000         DB   : NCTEST
APPHDL  : 0-49794              APPID: 20.10.80.247.48084.121120015251
AUTHID  : NCTEST  
EDUID   : 3796                 EDUNAME: db2agent (NCTEST) 0
FUNCTION: DB2 UDB, buffer pool services, sqlbAllocateExtent, probe:840
MESSAGE : ADM6044E  The DMS table space "NNC_INDEX01" (ID "5") is full.  If 
          this is an autoresize or automatic storage DMS tablespace, the 
          maximum table space size may have been reached or the existing 
          containers or storage paths cannot grow any more. Additional space 
          can be added to the table space by either adding new containers or 
          extending existing ones using the ALTER TABLESPACE SQL statement. If 
          this is an autoresize or automatic storage DMS table space, 
          additional space can be added by adding containers to an autoresize 
          table space or by adding new storage paths to an automatic storage 
          database.
2012-11-20-10.00.33.551000+480 I27659424F1147     LEVEL: Warning
PID     : 2276                 TID  : 3796        PROC : db2syscs.exe
INSTANCE: DB2                  NODE : 000         DB   : NCTEST
APPHDL  : 0-49794              APPID: 20.10.80.247.48084.121120015251
AUTHID  : NCTEST  
EDUID   : 3796                 EDUNAME: db2agent (NCTEST) 0
FUNCTION: DB2 UDB, buffer pool services, sqlbObtainDataExtent, probe:800
MESSAGE : ZRC=0x85020021=-2063466463=SQLB_END_OF_CONTAINER
          "DMS Container space full"
DATA #1 : Object descriptor, PD_TYPE_SQLB_OBJECT_DESC, 88 bytes
    Obj: {pool:5;obj:11020;type:1} Parent={4;1360}
  lifeLSN:       000000005AAC4D6E
  tid:           0 0  0
  extentAnchor:               78560
  initEmpPages:                   0
  poolPage0:                      0
  poolflags:                    102
  objectState:                   27
  lastSMP:                        0
  pageSize:                    4096
  extentSize:                    32
  bufferPoolID:                   2
  partialHash:            705429509
  bufferPool:    0x000000001a7837a0
  pdef:          0x000000001a804160
从上述错误来看,是表空间NNC_INDEX01表空间被占满了。
看下NNC_INDEX01表空间使用情况:
db2 => list tablespaces show detail
发现可用页数已经变成了0。
查看报错的地方,是一个绑定变量+Batch的操作。insert into IC_ATP_F,这个表有一个主键索引,而批量插入的时候肯定会用到索引表空间。
添加一个容器,alter tablespace nnc_index01 add (file '\db2\nnc_index01_2' 204800) 
再次执行,问题解决。
 
转自:http://www.cnblogs.com/zhaoshuangshuang/archive/2012/11/20/2779797.html

 

### 如何在 MySQL 8.0 中使用 JDBC 进行批处理操作 在 MySQL 8.0 中,可以通过 JDBC 执行批量更新来提高性能。以下是关于如何设置和执行批处理的具体细节。 #### 配置连接字符串 为了支持批处理功能,需要正确配置 `DataSource` 或者直接通过 YAML 文件定义数据库连接参数。例如: ```yaml spring: datasource: druid: url: jdbc:mysql://127.0.0.1:3306/testdb?rewriteBatchedStatements=true&useServerPrepStmts=true&cachePrepStmts=true username: root password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver ``` 这里的关键在于 URL 参数中的几个选项: - **`rewriteBatchedStatements=true`**: 启用 MySQL 自动优化批处理语句的功能[^1]。 - **`useServerPrepStmts=true` 和 `cachePrepStmts=true`**: 提高预编译语句缓存效率并减少网络开销[^1]。 #### 实现批处理逻辑 下面是一个完整的 Java 示例代码展示如何利用 JDBC API 来完成批处理操作: ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class JdbcBatchExample { public static void main(String[] args) throws Exception { String dbUrl = "jdbc:mysql://127.0.0.1:3306/testdb?rewriteBatchedStatements=true"; String user = "root"; String pass = "123456"; try (Connection conn = DriverManager.getConnection(dbUrl, user, pass)) { conn.setAutoCommit(false); // 关闭自动提交模式 String sql = "INSERT INTO users(name, age) VALUES (?, ?)"; try (PreparedStatement pstmt = conn.prepareStatement(sql)) { for (int i = 1; i <= 100; i++) { // 假设插入100条记录 pstmt.setString(1, "User" + i); pstmt.setInt(2, i * 10); pstmt.addBatch(); // 添加到批处理队列 if (i % 20 == 0) { // 每20次调用 executeBatch() pstmt.executeBatch(); } } pstmt.executeBatch(); // 处理剩余部分 } conn.commit(); // 提交事务 } catch (Exception e) { System.err.println(e.getMessage()); } } } ``` 这段程序展示了以下几个要点: - 使用 `addBatch()` 方法将 SQL 语句加入批次中。 - 调用 `executeBatch()` 将累积的 SQL 一次性发送给服务器执行。 - 设置合理的分组大小(如每 20 条执行一次),以平衡内存占用与性能提升[^1]。 #### 错误处理机制 当某一条 SQL 出错时,默认情况下整个批处理会失败。如果希望逐条回滚错误,则需启用继续模式: ```java conn.setSavepoint(); // 创建保存点以便后续恢复状态 try { stmt.executeBatch(); } catch (SQLException ex) { while (ex != null && !(ex instanceof BatchUpdateException)) { ex.printStackTrace(); ex = ex.getNextException(); } int[] updateCounts = ((BatchUpdateException) ex).getUpdateCounts(); for (int count : updateCounts) { if (count >= 0 || count == Statement.SUCCESS_NO_INFO) { continue; // 成功或者无信息跳过 } else if (count == Statement.EXECUTE_FAILED) { throw new RuntimeException("One of the statements failed."); } } } ``` 以上片段解释了如何捕获异常以及获取各子查询的结果集长度数组[^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值