jdbctemplate 批量操做

public void addUserBean(List<UserBean> list) 
	{ 
	   final List<UserBean> tempBpplist = list; 
	   String sql="insert into user(id,name,isgood)" +
	   		" values(?,?,?)"; 
	   jdbcTemplateMysql.batchUpdate(sql,new BatchPreparedStatementSetter() {

			@Override
			public int getBatchSize() {
				 return tempBpplist.size(); 
			}
			@Override
			public void setValues(PreparedStatement ps, int i)
					throws SQLException {
				  ps.setInt(1, tempBpplist.get(i).getId()); 
			      ps.setString(2, tempBpplist.get(i).getName()); 
			      ps.setBoolean(3, tempBpplist.get(i).isGood()); 
			} 
	  }); 
	}
相關文章
相關標籤/搜索