首先在项目中导入bboss 持久层包:
maven坐标
gradle坐标
compile 'com.bbossgroups:bboss-persistent:5.1.8'
轻量级批处理方法
直接操作sql语句的组件SQLExecutor
com.frameworkset.common.poolman.SQLExecutor
public staticvoid executeBatch(String sql,List datas,int batchsize, BatchHandler batchHandler) throws SQLException //指定数据源dbname public static void executeBatch(String dbname,String sql,List datas,int batchsize, BatchHandler batchHandler) throws SQLException
加载sql配置文件的组件ConfigSQLExecutor
com.frameworkset.common.poolman.ConfigSQLExecutor
publicvoid executeBatch(String sqlname,List datas,int batchsize, BatchHandler batchHandler) throws SQLException //指定数据源dbname public void executeBatch(String dbname,String sqlname,List datas,int batchsize, BatchHandler batchHandler) throws SQLException
批处理语句参数设置器:
package com.frameworkset.common.poolman; /** * 轻量级jdbc批处理操作记录设置器 */ import java.sql.PreparedStatement; import java.sql.SQLException; public interface BatchHandler{ /** * * @param stmt jdbc PreparedStatement parameterIndex the first parameter is 1, the second is 2, ... * x the parameter value * @param record 当前操作的变量 * @param i 行索引 * @throws SQLException */ public void handler(PreparedStatement stmt,T record,int i) throws SQLException; }
使用实例
以SQLExecutor组件来做为例子介绍如下:
@Test public void testBatch() throws SQLException { List