mac*_*ers 6 sql sql-server spring stored-procedures jdbc
我正在使用Spring JDBCTemplate连接到SQL Server.
我有一个需要插入SQL Server表的对象列表.
我做的是以下内容:
public void batchInsert(final List<Bean> list) {
final String sql = "insert into temp"
+ "(id, name, amount, location, time, price) "
+ " values (?, ?, ?, ?, ?, ?)";
getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Bean vo = list.get(i);
ps.setString(1, vo.getId());
ps.setString(2, vo.getName());
ps.setDouble(3, vo.getAmount());
ps.setString(4, vo.getLocation());
ps.setString(5, vo.getTime());
ps.setDouble(6, vo.getPrice());
}
@Override
public int getBatchSize() {
return list.size();
}
});
}
Run Code Online (Sandbox Code Playgroud)
但是现在,我想将参数List<Bean> list传递给存储过程,该存储过程尽可能高效地处理批量插入.
请问如何实现这个?
| 归档时间: |
|
| 查看次数: |
2558 次 |
| 最近记录: |