使用 usingGeneratedKeyColumns遇到的问题

来源:互联网 发布:子弹最快速度知乎 编辑:程序博客网 时间:2024/06/05 14:17

 

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

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

原创粉丝点击