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 8765259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:14:13+00:00 2026-06-13T16:14:13+00:00

I have a store program in java and a database made in access. I

  • 0

I have a store program in java and a database made in access. I already have 2 tables in my database which are the customers table and the products table.

I want to add an orders table wherein it’s primary key is an autonumber and an order_line table to complete this app. I want to have tables like this..

customer(cust_id, name, ....)
orders(order_no, cust_id, date_purchased,...)
order_line(order_no, product_id, ...)
products(product_id, product_name, price,....)

When the customer purchased the products, i could insert new values to the orders table. The thing that is not clear to me is how could i insert also in the order_line table, because the order_no I created in access is of type autonumber.

Would I make a select statement first to get the order_no value to put it to the order_no in order_line’s table? Or I need to put this in one query only.

Anyone with experience to this? Any advice is appreciated.

  • 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-13T16:14:15+00:00Added an answer on June 13, 2026 at 4:14 pm

    The insertion into orders and order_line table should happen in a single transaction. While doing so, if you are using plain JDBC to insert record into orders table, you can register the order_no as an OUT parameter in your CallableStatement and get the value after the statement is executed and use to set the order_no attribute on the order_line records.

     // begin transaction
     connection.setAutoCommit(false);
    
     CallableStatement cs = connection.prepareCall(INSERT_STMT_INTO_ORDERS_TABLE);
     cs.registerOutParameter(1, Types.INT);
     int updateCount = cs.execute();
     // Check the update count.
     long orderNo = cs.getInt(1);
    
     // CallableStatement csLine for inserting into order_line table
     // for (OrderLine line: orderLines) {
     //     Set the orderNo in line.
     //     set paramters on csLine.
     //     csLine.addBatch();
     // }
     // run the batch and verify update counts
     connection.commit();
    
     // connection.rollback() on error.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have connected Java program to Oracle database using JDBC. I want to store
I have a java program which uses arraylists - these arraylists store 'variables' where
I have made a program in Java which is used to collect medical data
I have a C program that stores some object in java store using JNI.
I have a program in which I need to store a Class object into
I have Java program where I create a file called hd_details , and store
I have stored some data in MySQL database through a java program. Now I
I have a single user java program that I would like to have store
I have a requirement for a program I'm working on to store job numbers
I am to connect to a MySQL database from a Java application to store

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.