its duplicate question with Get last inserted auto increment id in mysql
I'm creating a group it insert on M_GROUPS.
M_GROUPS table:
GROUP_ID INT AUTO_INCREMENT, GROUP_CREATOR_ID INT which from session.
I need to take GROUP_ID and GROUP_CREATOR_ID and insert it on
M_GROUP_MEMBERS table as
GROUP_ID INT, MEMBER_ID INT. My problem is I can't take auto increment value GROUP_ID from M_GROUPS
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(); } } }