当前位置:Gxlcms > 数据库问题 > Spring BatchSqlUpdate.updateByNamedParam例子

Spring BatchSqlUpdate.updateByNamedParam例子

时间:2021-07-01 10:21:17 帮助过:15人阅读

dstColCount=dstColNamesList.size(); String insSql="insert into "+tableName+"("+dstTableInsColSql+") values("+dstTableInsValueSql+")"; BatchSqlUpdate bsu=new BatchSqlUpdate(); bsu.setDataSource(jdbcService.getJdbcTempalte().getDataSource()); bsu.setSql(insSql); bsu.setBatchSize(1000); for (int i = 0; i < dstColCount; i++) { SqlParameter sp=new SqlParameter(dstColNamesList.get(i),java.sql.Types.VARCHAR); bsu.declareParameter(sp); } // 生成插入到当前数据库的有关脚本 while (srcRecords.next()) { for (int i = 0; i < dstColCount; i++) { paramsMap.put(dstColNamesList.get(i), srcRecords.getString(srcColNamesList.get(i))); } bsu.updateByNamedParam(paramsMap); }
1)SqlParameter有多种构造函数,具体可以看官方文档
2)由于是命名参数,所以sql的参数必须定义为 冒号+名称,例如:name,:sex.
3)SqlParameter中参数的名称必须和sql中的对应
4)updateByNamedParam中Map的key名称必须和 sql中参数名称对应
效率上尚未深入测试,有机会做个测试看看!

Spring BatchSqlUpdate.updateByNamedParam例子

标签:param   char   lte   date()   date   count   sql   table   for   

人气教程排行