The Artima Developer Community
Sponsored Link

Java Answers Forum
SQL Insert problem

2 replies on 1 page. Most recent reply: Jul 9, 2002 7:09 PM by Nicolas

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Nicolas

Posts: 3
Nickname: nico
Registered: Jul, 2002

SQL Insert problem Posted: Jul 8, 2002 11:12 PM
Reply to this message Reply
Advertisement
Is there is anybody help me. This is urgent to use.
The problem is:
When I create two or more table with constraint on both.
Eg.
I have an Order table which is have the structur like this :
ID Identity ( Primary Key )
Order_No
Date
Remark

And then I have another one table name Sub_Order which is contain the detail of the order like this:
OrderID ( Contraint to Order ID )
Product
Pieces
Price

I like to save it together when I save the Order data. The problem is the ID field in the Order table will only generated when I have Insert to table Order. So, how I can get the ID from Order and then save it to Sub_Order table.

Note: That is just a sample table. And for note Order_No can't be a Primary Key.

Thank you.


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: SQL Insert problem Posted: Jul 9, 2002 9:18 AM
Reply to this message Reply
If you are working with JDBC version prior to 3.0 then you have only one solution and that is to execute a query to get the generated PK from order table. In this case , you may not have all columns values that can fetch you unique key value. However, in JDBC3.0, this problem has been solved and you can fetch the auto generated key values as follows.
your_statement.executeUpdate ( "insert into order ( your_column_name_list ) values ( your_values_list )", Statement.RETURN_GENERATED_KEYS ) ;
ResultSet rs = your_statement.getGeneratedKeys() ;
// Now your resultset rs will have the generated keys
 

For details , please refer to:
http://java.sun.com/javaone/javaone2001/pdfs/1135.pdf

Nicolas

Posts: 3
Nickname: nico
Registered: Jul, 2002

Re: SQL Insert problem Posted: Jul 9, 2002 7:09 PM
Reply to this message Reply
Where should I find the JDBC 3.0 compatible for AIX system. What should I do to make it compatible.

Flat View: This topic has 2 replies on 1 page
Topic: I dont want to print whole frame Previous Topic   Next Topic Topic: packaging ear files

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use