0

I have a line of code that works for SqlServer, and wondering if this would work for Oracle. Here is my query:

INSERT INTO event_master (event_id, user_id, type, detail, status, update_timestamp)
VALUES (event_master_id_seq.nextval, :user_id, :type, :detail, :status, :update_timestamp)

and here is my code:

        MapSqlParameterSource parameters = new MapSqlParameterSource();
        parameters.addValue("user_id", event.getActionAccount().getUser().getId());
        parameters.addValue("type", event.getType());
        parameters.addValue("detail", event.getDetail());
        parameters.addValue("status", event.getStatus());
        parameters.addValue("update_timestamp", new java.sql.Timestamp(Instant.now().toEpochMilli()));
        long eventId = jdbcTemplate.queryForObject(insertEventMaster, parameters, Long.class);
        return eventId;

event_id is primary key and when this code runs and insert into database, I want this generated event_id. I found other ways around it, but I want to see if this would work. I have an environment where I can't test this locally right now..

Jonathan Hagen
  • 580
  • 1
  • 6
  • 29
  • What version of Oracle? What JDBC driver / version you using? Please [edit] your question and add that information, and add a tag for the Oracle version, such as `oracle12c` – Mark Stewart Sep 23 '20 at 13:28
  • This should get you what you need https://stackoverflow.com/questions/17459094/getting-id-after-insert-within-a-transaction-oracle – Sujitmohanty30 Sep 23 '20 at 17:26

0 Answers0