spring jdbcTemplate 插入对象返回主键值

ScaNIV的头像 ScaNIV 0 2016-03-04 14:54 0


× 1   

浏览数: 26134

分享时间: 2 年 前

public int addClifford(Clifford clifford) {
    String sql = "insert into t_user_clifford(mobile,last_activity_date,clifford_count,is_share)values(?,?,?,?)";
    int idResult = 0;
    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplateActivityWrite.update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
            PreparedStatement ps = connection.prepareStatement(sql,PreparedStatement.RETURN_GENERATED_KEYS);
            return ps;
    idResult = keyHolder.getKey().intValue();
    return idResult;

  • ossaa的头像 ossaa 2018-09-02 18:28 代码数:0

    This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post! Toronto Homes Canada

  • ossaa的头像 ossaa 2018-09-06 23:02 代码数:0

    It is imperative that we read blog post very carefully. I am already done it and find that this post is really amazing.

    EMS Geräte

  • cixexey 的头像 cixexey 2018-09-17 20:56 代码数:0

    I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. tech tips

  • pevahanifo的头像 pevahanifo 2018-09-22 19:21 代码数:0

    I have read your article, it is very informative and helpful for me.I admire the valuable information you offer in your articles. Thanks for posting it.. technology and business tips

  • cixexey的头像 cixexey 2018-08-20 19:06 代码数:0

    I really appreciate the kind of topics you post here. Thanks for sharing us a great information that is actually helpful. Good day! suzuki coin

  • cixexey的头像 cixexey 2018-08-24 19:15 代码数:0

    Thank you so much for the post you do. I like your post and all you share with us is up to date and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. Michigan Personal Injury Law Firm

  • AsharSeo的头像 AsharSeo 2018-10-12 05:50 代码数:0

    The post is composed in exceptionally a decent way and it contains numerous helpful data for me.



  • 淡淡人生的头像 淡淡人生 2016-03-04 15:08 代码数:0
  • pevahanifo的头像 pevahanifo 2018-08-26 14:15 代码数:0

    I just want to let you know that I just check out your site and I find it very interesting and informative..Tile Cleaning