- public int insertTable(LabelForm f) throws SQLException,ParseException
- {
- String content = f.getSiteId();
- final String sql = "insert into TAG_INFO(SITE_ID,NAME,CONTENT) values(?,?,'"+content+"')";
- KeyHolder keyHolder = new GeneratedKeyHolder();
- getJdbcTemplate().update(
- new PreparedStatementCreator() {
- public PreparedStatement createPreparedStatement(Connection con) throws SQLException
- {
- PreparedStatement ps = getJdbcTemplate().getDataSource()
- .getConnection().prepareStatement(sql,new String[]{ "SITE_ID" ,"NAME"});
- ps.setString(1, "站点号");
- ps.setString(2, "我的名字");
- return ps;
- }
- }, keyHolder);
- System.out.println("自动插入id============================" + keyHolder.getKey().intValue());
- return keyHolder.getKey().intValue();
- }
Spring JdbcTemplate返回插入记录的自增Id
最新推荐文章于 2024-09-05 22:02:47 发布