当前位置:网站首页>Jdbctemplate inserts and returns the primary key

Jdbctemplate inserts and returns the primary key

2022-06-12 21:26:00 Besieged city_ city with high walls

public static int getMemberId(JdbcTemplate jdbcTemplate, int orgId) {
    
    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplate.update(con ->  {
    
        String sql="INSERT INTO t_g_primarykey(ord_id,create_time,day_time) VALUES(?,?,?)";
        PreparedStatement ps = con.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
        ps.setInt(1, orgId);
        ps.setLong(2, ComDateUtils.getUnixCurrTime());
        ps.setLong(3,DateUtil.getTodayZeroTimeTemp());
        return ps;
    }, keyHolder);
    return Optional.ofNullable(keyHolder.getKey()).orElse(0).intValue();
}
原网站

版权声明
本文为[Besieged city_ city with high walls]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206122125175220.html