`
heipark
  • 浏览: 2094878 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics