I have 2 tables (table1, table2) table1 has a field id and table2 has a field id\_eid that reference the id field of table1 as foreign key.

I have to delete from table1 all the rows that match a determinated criteria and then if these data are referenced in table2 delete the data from it too.

I do something like that, assuming `con` is the Connection object and autocommit is set to false on it.

```
    String query1 = "delete from table2 where exists 
(select * from table1 where someparameter = ? and table1.id = table2.id_eid)"

```

then i execute the first query1 using PreparedStatement.

then i have 

```
    String query2 = "delete from table1 where someparameter = ? 
and exists (select * from table2 where table1.id = table2.id_eid)"

```

and i executed this with another PreparedStatment.

at the end i have the `con.commit()`.

This doesn't work, i was thinking using autocommit to false the two queries was executed together but it is not, the second query deletes no rows, how can i do this ?

An important note, not all the rows in table1 have a referenced row in table2.

Thanks