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

spring jdbcTemplate 返回主键糟糕解决办法
		KeyHolder keyHolder = new GeneratedKeyHolder();
		jdbcTemplate.update(new PreparedStatementCreator() {
			public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
				PreparedStatement ps = connection.prepareStatement(
						"INSERT INTO Test (id, NAME) VALUES (phoenix_sequence.nextval,?)", new String[] { "ID" });
				ps.setString(1, "heipark");
				return ps;
			}
		}, keyHolder);
		Long generatedId = keyHolder.getKey().longValue();
		System.out.println(generatedId);


还不如:
select phoenix_sequence.nextval from dual