File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes 2 inserts - urgent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "2 inserts - urgent" Watch "2 inserts - urgent" New topic
Author

2 inserts - urgent

saquib nisar
Greenhorn

Joined: Nov 13, 2000
Posts: 14
I need to insert two records into a Oracle DB, which are linked via object id's which are generated from a sequence.
So, the code would be:
Create Record1
Set Record1.Id = some sequence
Create Record2
Record2.Link = Record1.Id
But, once I have created record1 how do I know which record was created, or with which sequence?
Please help.
snisar@caluk.com
Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
Can you just run a SELECT statement to get the sequence number and store it in a variable for later use?
long sequenceNum = 0;
ResultSet rs = Statement.executeQuery("select sequence_name.nextval from dual");
if (rs.next() ) sequenceNum = rs.getLong(1);
Brian
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2 inserts - urgent
 
Similar Threads
Is notifyAll good enough?
delete record, update gui
Create a Different selectOneListbox Depending On the Radio Button Clicked
Subqueries in JPA is not working with OpenJPA
Reading an XLS (Excel) file. Row by row.