当前位置: 代码迷 >> 综合 >> //插入很多书(批量插入用法)jdbcTemplate
  详细解决方案

//插入很多书(批量插入用法)jdbcTemplate

热度:75   发布时间:2023-12-08 02:09:07.0
//插入很多书(批量插入用法)
public void insertBooks(List<Book> book)
{
final List<Book> tempBook=book;
String sql="insert into book(name,pbYear) values(?,?)";
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter()
{
public void setValues(PreparedStatement ps,int i)throws SQLException
{
String name=tempBook.get(i).getName();
int pbYear=tempBook.get(i).getPbYear();
ps.setString(1, name);
ps.setInt(2, pbYear);
}
public int getBatchSize()
{
return tempBook.size();
}
});

}
  相关解决方案