【发布时间】:2014-03-14 05:32:07
【问题描述】:
与Get last inserted auto increment id in mysql 重复的问题
我正在创建一个在M_GROUPS 上插入的组。
M_GROUPS表:
GROUP_ID INT AUTO_INCREMENT,
GROUP_CREATOR_ID INT
来自会话。
我需要将GROUP_ID 和GROUP_CREATOR_ID 插入到M_GROUP_MEMBERS 表中
GROUP_ID INT,
MEMBER_ID INT.
我的问题是我不能从M_GROUPS 获取自动增量值GROUP_ID
public void groupCreation(String groupname, int grouptype, int creator_id) {
DatabaseService oDatabaseService = new DatabaseService();
Connection connection = oDatabaseService.connect();
try {
Statement stmt = null;
stmt = connection.createStatement();
String sql;
sql = "INSERT INTO M_GROUPS( GROUP_NAME, GROUP_CREATOR_ID,
GROUP_TYPE, CREATION_TIME)"
+ " VALUES ('"
+ groupname
+ "','"
+ creator_id
+ "','"
+ grouptype + "',NOW())";
//stmt.executeUpdate(sql);
stmt.executeUpdate(sql);
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (connection != null)
connection.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
}
【问题讨论】: