先记录一下。遇到要使用自动增长的序列时,添加数据可以先查询一下序列号,设置再插入
String s = "select nextval('seq_collection_0') ";
try {
int guid = getNamedParameterJdbcTemplate().queryForInt(s, Collections.EMPTY_MAP);
t.setGuid((long)guid);
Map<String, Object> paramMap = SCollectionRowMapper.putCollectionMap(t);
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(getDataSource()).withTableName("s_collection_0")
.usingColumns("uid","type","remark","phone","parentid","name","luid","longitude","latitude","lasttime","guid",
"cityid","addtime","address");
return simpleJdbcInsert.execute(paramMap);
} catch (Exception e) {
return 0;
}
本文介绍了一种在数据库操作中使用自动增长序列的方法。通过查询序列号并将其设置为记录标识符,确保了每条数据的唯一性。具体实现包括获取序列号、设置标识符及使用SimpleJdbcInsert进行数据插入。
571

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



