下面给出的代码总是为最后一个插入 id 返回零。你能解释一下这段代码有什么问题吗?
JdbcTemplate insert = new JdbcTemplate(dataSource);
insert.update("INSERT INTO item (price, item_category) VALUES(?,?)",
new Object[] { beverage.getPrice(), beverage.getItemCategory() });
int id = insert.queryForInt( "SELECT last_insert_id()" );
System.out.println(id);
return insert.update("INSERT INTO beverage (id, name, quantity,size) VALUES(?,?,?,?)", new Object[] { id,beverage.getName(), beverage.getQuantity(),beverage.getSize() });