You could also write a database procedure that does the double insert for you. This
will be precompiled and stored on the database side. You can then use prepareCall()
and CallableStatement to call it. This will also make the double insert "atomic" (if
the either of the two inserts fail, they both do), which is probably easier than doing
rollbacks on the client side.
At 08:08 AM 5/12/99 -0400, you wrote:
>Tom,
>
>You need to have two prepared statements and make two separate insert
>calls, checking the return code for each.
>
>John
>
>
>Tom Kochanowicz wrote:
>>
>> In my servlet I used to have one table. For performance reasons
>> I broke the table into two tables. I can't get it to work now because
>> I'm not sure how to set up the prepared statement. Any Ideas or
>> examples
>> would be appreciated. Here is an example of BEFORE and AFTER
>>
>> BEFORE
>> registerStatement =
>> dbConnection.prepareStatement("insert into Classifieds "
>> + "(Name, Address, City, State, Zip, Email, Phone, PayMethod,
>> CardNumber, CardMo, CardYr, StartDate, EndDate, AmtForDayMoYr,
>> ClassifiedAd, WhatAdSays01, WhatAdSays02, WhatAdSays03, WhatAdSays04,
>> WhatAdSays05, WhatAdSays06, WebSite, UniqueDateId)"
>> + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
>> ?, ?, ?, ?)");
>>
>> AFTER (this doesn't work with two tables... can you tell me why?)
>> // First table
>> registerStatement =
>> dbConnection.prepareStatement(("insert into CustInfo
>> "
>> + "(UniqueDateId, Name, Address, City, State, Zip, PayMethod,
>> CardNumber, CardMo, CardYr, StartDate, EndDate, AmtForDayMoYr)"
>> + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
>> // Second table
>> + ("insert into AdInfo "
>> + "(UniqueDateId, ClassifiedAd, WhatAdSays01, WhatAdSays02,
>> WhatAdSays03, WhatAdSays04, WhatAdSays05, WhatAdSays06, Phone, Email,
>> WebSite)"
>> + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));
>
>___________________________________________________________________________
>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
>
===========================================================
Mike Lenahan Phone: (724) 742-6683
Internet Applications Developer Fax: (724) 742-6800
FORE Systems Inc. email: [EMAIL PROTECTED]
===========================================================
___________________________________________________________________________
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