> >From: robert young <[EMAIL PROTECTED]>
> >i need to use JDBC (dynamic SQL, not stored procedures),
> >to insert a parent table row, then one or more child
> >table rows where parent table Id is written into a
> >column (e.g. ParentTableID) in the child table rows,
> >thus supporting joining the two tables.
> >
> >while i can do this with ease using a bulk update where
> >i can generate the id's as variables without reference
> >to the underlying tables, i need to do this at the request
> >of a servlet, getting data passed in. i'm using db2, which
> >can produce an integer primary key on the fly. the passed
> >in data from the servlet is not sufficient to make a unique
> >identifier for the parent table row, so i need to use
> >either the db2 facility, or a managed control table.
> >
> >single table inserts aren't a problem with JDBC, but this
> >related table stuff has got me flummoxed.
Why can't you use a transaction?
ie: use Connection.setAutoCommit() to turn off the automatic
committing of inserts.
Then:
- use a query to obtain the unique id from DB2
- insert the parent record
- insert the child records
- commit
If an exception occurs anywhere then rollback.
As long as you're using a database that supports all this (and DB2
does) you should be ok.
Nic Ferrier
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html