标签:
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.PreparedStatementCreator; import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.KeyHolder; public class jdbcTest{ //setter and getter //..... //function final String sql="..."; KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException{ PreparedStatement ps = connection.prepareStatement(sql, PreparedStatement.RETURN_GENERAT ED_KEYS); ps.setString(1, "areaName"); ps.setInt(2, 98); //.... return ps; } }, keyHolder); return keyHolder.getKey().intValue(); }
标签:
原文地址:http://my.oschina.net/u/225373/blog/407375