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