日期:2014-05-16 浏览次数:20565 次
Statement stmt = conn.createStatement(); stmt.executeQuery("INSERT INTO table_name(...) values(...)",Statement.RETURN_GENERATED_KEYS); ResultSet rs = stmt.getGeneratedKeys(); if(rs.next()){ this.setId(rs.getInt(1)); }
Statement stmt = conn.createStatement(); stmt.executeQuery("INSERT INTO table_name(...) values(...)",Statement.RETURN_GENERATED_KEYS); ResultSet rs = stmt.executeQuery("SELECT LAST_INSERT_ID()"); if(rs.next()){ this.setId(rs.getInt(1)); }