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