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 JDBC进行批量数据插入的方法,并展示了如何通过预编译语句来获取自动生成的主键值。此外,还提供了一个简单的对比方法,即直接通过SQL查询获取序列值。
1387

被折叠的 条评论
为什么被折叠?



