batch update as a single transaction  
Author Message
John Harrison





PostPosted: 2004-10-1 1:13:00 Top

java-programmer, batch update as a single transaction Hi,

I'm doing a JDBC batch update, writing several thousand rows to a single
table. As I understand it a batch update can partially succeed, so some of
my rows might get written and some not. I'd like the batch update to either
fully succeed or completely fail, commit or rollback in other words. Is that
easy to do? I'm pretty new at this.

Thanks,
John


 
Joe Weinstein





PostPosted: 2004-10-1 1:58:00 Top

java-programmer >> batch update as a single transaction

John Harrison wrote:
> Hi,
>
> I'm doing a JDBC batch update, writing several thousand rows to a single
> table. As I understand it a batch update can partially succeed, so some of
> my rows might get written and some not. I'd like the batch update to either
> fully succeed or completely fail, commit or rollback in other words. Is that
> easy to do? I'm pretty new at this.

Yes, easy. Set autoCommit(false) on the connection (so any subsequent work
needs to be committed). Then do batch. Check return array or whatever else
you need to do to verify whether everything went OK. If it did, call commit()
on the connection, else call rollback().

Joe Weinstein at BEA
>
> Thanks,
> John
>
>

 
John Harrison





PostPosted: 2004-10-1 2:06:00 Top

java-programmer >> batch update as a single transaction
"Joe Weinstein" <email***@***.com> wrote in message
news:email***@***.com...
>
>
> John Harrison wrote:
> > Hi,
> >
> > I'm doing a JDBC batch update, writing several thousand rows to a single
> > table. As I understand it a batch update can partially succeed, so some
of
> > my rows might get written and some not. I'd like the batch update to
either
> > fully succeed or completely fail, commit or rollback in other words. Is
that
> > easy to do? I'm pretty new at this.
>
> Yes, easy. Set autoCommit(false) on the connection (so any subsequent work
> needs to be committed). Then do batch. Check return array or whatever else
> you need to do to verify whether everything went OK. If it did, call
commit()
> on the connection, else call rollback().
>

OK thanks, amazingly enough that was what I was doing already.

john