Re: handling multiple queries
Posted by: Mark Matthews
Date: August 05, 2005 10:32AM

ms wrote:
> Hi,
>
> Is it possible to issue multiple queries in one
> 'stmt.executeUpdate' call by separating them with
> a semicolon?
>
> Or should I just use transactions?
>
> I have some code that does the following (each
> 'newspaper' row has a foreign key to the
> papercodes.id column:
>
> Connection con = getBroker().getConnection();
> String query = "DELETE FROM papercodes WHERE id in
>
> (select papercodeid from
> newspapers where id = 2";
>
> Statement stmt = con.createStatement();
> query = "DELETE FROM newspapers WHERE id=2";
>
> But what happens if statement 1 succeeds but
> statement two fails (due to connection or
> whatever?). I am left with a bad newspaper....
>
> So I guess I should use transactions to handle
> this?

MS,

Yes. This is exactly what transactions are for. Multple queries does not make the operation atomic, it just saves a network round-trip per each query that you specify in the list.

-Mark

Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools
Oracle
http://www.mysql.com/products/enterprise/monitor.html

Options: ReplyQuote


Subject
Written By
Posted
ms
August 05, 2005 09:04AM
Re: handling multiple queries
August 05, 2005 10:32AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.