sping 使用mysql 函数 LAST_INSERT_ID() 的错误
--------------------编程问答-------------------- 有高手帮我看看啊 --------------------编程问答-------------------- 帮忙看看。。。。。。。。。。。。。 --------------------编程问答-------------------- final KeyHolder keyHolder = new GeneratedKeyHolder();final Thread thread = new Thread();
thread.setGroupId(groupId);
thread.setLastUpdatedAt(DateUtils.newDate());
super.getJdbcTemplate().update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement preparedStatement = connection.prepareStatement(INSERT_THREAD,
Statement.RETURN_GENERATED_KEYS);
preparedStatement.setObject(1, thread.getGroupId());
preparedStatement.setObject(2, UserContext.getCurrentUserId());
preparedStatement.setObject(3, thread.getLastUpdatedAt());
return preparedStatement;
}
}, keyHolder);
logger.debug("insert thread: {}", INSERT_THREAD);
thread.setId(((Long) keyHolder.getKey()).intValue());
-----------------------------------------
keyHolder可以获得你插入数据库的那个主键值
补充:Java , Java EE