使用 usingGeneratedKeyColumns遇到的问题

本文介绍了一种在数据库操作中使用自动增长序列的方法。通过查询序列号并将其设置为记录标识符,确保了每条数据的唯一性。具体实现包括获取序列号、设置标识符及使用SimpleJdbcInsert进行数据插入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先记录一下。遇到要使用自动增长的序列时,添加数据可以先查询一下序列号,设置再插入

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值