import org.springframework.jdbc.core.PreparedStatementCreator; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.support.GeneratedKeyHolder; final String sql = "insert into riv_outbound_no_seq(seq_name) values('onh_notice_no')"; KeyHolder keyHolder1 = new GeneratedKeyHolder(); String onhNoticeNo = null; jdbcTemplate.getJdbcOperations().update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement(sql, new String[] {"seq"}); return ps; } }, keyHolder1); if (null != keyHolder1.getKey()) { String currDate = CommonMethodHelper.convertDate2String("yyyyMMdd"); String serialNo = String.format("%09d", keyHolder1.getKey()); onhNoticeNo = "OBN" + currDate + serialNo; onh.setOnhNoticeNo(onhNoticeNo); }
CREATE TABLE `riv_outbound_no_seq` ( `seq` bigint(7) unsigned zerofill NOT NULL AUTO_INCREMENT, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `seq_name` varchar(40) NOT NULL, PRIMARY KEY (`seq`) ) ENGINE=InnoDB AUTO_INCREMENT=12176347 DEFAULT CHARSET=utf8;