jdbcTemplate批量处理

1:sql中的占位符一定不要用引号 

private void baskHist(final List<String[]> userBillingOrChannel) {
		String sqlFiled = DateFormatUtils.format(Calendar.getInstance().getTime(), "yyyyMM");
		String sql = "INSERT into user_to_billing (user_id,billing_id,bak_date) VALUES (?,?,'"+ sqlFiled + "')";
		jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

			@Override
			public void setValues(PreparedStatement ps, int i)
					throws SQLException {
				String[] data = userBillingOrChannel.get(i);
				ps.setString(1, data[0]);
				ps.setString(2, data[1]);
			}
			@Override
			public int getBatchSize() {
				return userBillingOrChannel.size();
			}
		});
		
		logger.info("The backup successful. ");
	}

 

你可能感兴趣的:(JdbcTemplate)