Transactions controlling database inserts and Vectors

M

Marcus Leon

How can you put database modifications and access to Java collections
in one transaction?

For example, have one transaction where you insert a row into a
database and add an object to a Vector? If an exception is thrown,
then the database insert is rolled back and the object is not added to
the Vector.

Thanks
 
E

enrique

In a try-catch block, put the rollback and return statement in the
"catch", and the Vector operation somewhere below that.

try
{
MyObject o = sqlInsert(mySQLstatement);
}
catch (DBException e)
{
rollback();
return;
}

myVector.add(o);
 
S

shakah

enrique said:
In a try-catch block, put the rollback and return statement in the
"catch", and the Vector operation somewhere below that.

try
{
MyObject o = sqlInsert(mySQLstatement);
}
catch (DBException e)
{
rollback();
return;
}

myVector.add(o);

Alternatively:

try {
MyObject o = sqlInsert(mySQLstatement);
myVector.add(o);
}
catch (DBException e) {
rollback();
}

return ;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top