Vagrant- 2014-10-14 08:57 采纳率: 0%
浏览 1354

得到主键自动增长值KeyHolder

为什么我的代码执行后KeyHolder的值还是为空呢?
`public class UserDaoImpl implements IUserDao {
private NamedParameterJdbcTemplate simpleJdbcTemplate = new NamedParameterJdbcTemplate (JDBCUtils4.getDataSource());
@Override
public boolean addUser(RegistForm registForm) throws Exception {
//使用命名参数来给"?"占位符命名
String sql = "insert into user(username,birthday,major,score) values(:username,:birthday,:major,:score)";
//给各个占位符赋值
SqlParameterSource param = new BeanPropertySqlParameterSource(registForm);
//执行更新操作
KeyHolder keyHoder = new GeneratedKeyHolder();
int count = this.simpleJdbcTemplate.update(sql, param, keyHoder);

            System.out.println("-------------------------------"+keyHoder+"----------------------");
            int id = keyHoder.getKey().intValue();

            registForm.setId(id);
            if(count>0)
                return true;
            else 
                return false;
        }
}

`

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?