Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:40:38+00:00 2026-06-15T01:40:38+00:00

Possible Duplicate: How to get the insert ID in JDBC? I have the following

  • 0

Possible Duplicate:
How to get the insert ID in JDBC?

I have the following tables:

customer(cid, ...)

book(cid, rid)

reservation(rid, ...)

I want to add a reservation in its table then I want to add in a relationship in book between customer and reservation.

How can I know rid while it is auto generated, and when I execute the query I did get a ResultSet returned?

The rid is auto generated form Oracle using a sequence and a trigger.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:40:40+00:00Added an answer on June 15, 2026 at 1:40 am

    Refer to your question I believe you are using statements. In this case, you can use Statement.RETURN_GENERATED_KEYS. Also please consider this link as below solution can have conficts for Oracle database.

    Here is small example:

    Connection connection = database.getConnection();
    PreparedStatement statement = connection.prepareStatement(myQuery, Statement.RETURN_GENERATED_KEYS);
    int count = statement.executeUpdate();
    if(count <= 0){
     //value not inserted
    }
    
    ResultSet results = statement.getGeneratedKeys();
    
    if(results.next){
     System.out.println(generatedKeys.getLong(1));
    }
    

    in case of you are using ORM:

    If you are using JPA entitiyManager.merge(entity); (or update) should return persisted instance with ID.
    Quite similar with hibernate session.merge(entity); (or update)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to get the insert ID in JDBC? Hi, I'm using JDBC
Possible Duplicate: Best way to get identity of inserted row? I have an INSERT
Possible Duplicate: Get generated id after insert I want to get the last inserted
Possible Duplicate: Get full path of a file with FileUpload Control I want to
Possible Duplicate: Get script of SQL Server data I want to move some rows
Possible Duplicate: How to get offline cookies data with php and insert it in
Possible Duplicate: How to get last inserted id? I have a table Absences |
Possible Duplicate: php - insert a variable in an echo string I have a
Possible Duplicate: Access Auto-Increment Value During INSERT INTO Statement I want to run an
Possible Duplicate: How to get Insert id in MSSQL in PHP? I MYSQL I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.