问题
I have:
public void addJobs(Jobs jobs) {
this.getJdbcTemplate().update(sqlAddJobs, new Object[] {jobs.getJobName()});
}
In Postgresql DBI have a table:
row_id | jobs
row_id is auto increment, how can I got last insert id?
My sql:
INSERT INTO jobs (jobs) VALUES (?)
回答1:
One easy option is to make the query like:
"INSERT INTO jobs(jobs) VALUES(?) RETURNING row_id"
And execute int id = getJdbcTemplate().queryForInt(sql)
.
来源:https://stackoverflow.com/questions/12819077/spring-jdbctemplate-postgresql-last-insert-id