Spring3.0.5 获取表中自增的主键(mysql)

Spring3.0.5  获取表中自增的主键(mysql)
    public int addWsstxCotent(final WsstxContent wsstxContent) {
        final String sql = "insert into wsstx_content(sstx_type,sstx_content,sstx_title,opr_time,ts_tag) values(?,?,?,now(),?)";
//        this.jdbcTemplate.update(sql,
//                new Object[]{wsstxContent.getSstxType(), wsstxContent.getSstxContent(),wsstxContent.getSstxTitle(), wsstxContent.getTsTag()});
        KeyHolder keyHolder = new GeneratedKeyHolder();  
        this.jdbcTemplate.update(
                new PreparedStatementCreator() {
                    public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
                        PreparedStatement ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                        ps.setInt(1, wsstxContent.getSstxType());
                        ps.setString(2, wsstxContent.getSstxContent());
                        ps.setString(3, wsstxContent.getSstxTitle());
                        ps.setString(4, wsstxContent.getTsTag());
                        return ps;
                    } 
                } ,  keyHolder);
        int generatedId = keyHolder.getKey().intValue();
        return generatedId;
    }
Spring3.0.5  获取表中自增的主键(mysql)

 

Spring3.0.5 获取表中自增的主键(mysql),布布扣,bubuko.com

Spring3.0.5 获取表中自增的主键(mysql)

上一篇:Photoshop 建筑照片处理成绝美的夜景图


下一篇:Oracle 学习笔记(二)