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

你可能感兴趣的:(java,spring)