日期:2014-05-16  浏览次数:20470 次

jdbcTemplate获取刚插入的ID
final String sqlSave = sql.toString();
			final List<Object> argsSave = args;
			KeyHolder keyHolder = new GeneratedKeyHolder();
			jdbcTemplate.update(new PreparedStatementCreator() {
				@Override
				public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
					PreparedStatement ps = con.prepareStatement(sqlSave, Statement.RETURN_GENERATED_KEYS);
					for (int i = 0; i < argsSave.size(); i++) {
						ps.setObject(i + 1, argsSave.get(i));
					}
					return ps;
				}
			}, keyHolder);
			code = String.valueOf(keyHolder.getKey().intValue());

?