2

Can anyone explain to me, why this mysql script works on my Mysql Workbench and not on my tomcat server?

SET SQL_SAFE_UPDATES=0;
    Delete from t_dependant 
where
    pk_dependant in (select 
        *
    from
        (select 
            pk_dependant
        from
            t_dependant
        where
            fk_master = $pk_master_to_delete) x );
Delete from t_master 
where
    pk_master = pk_master_to_delete;

MySQLSyntaxErrorException (id=3440)

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELETE FROM t_dependant WHERE pk_dependant in (SELECT * FROM (SELECT pk_dependant a' at line 1

EDIT:

This is the code I run on the tomcat server:

java.sql.PreparedStatement prestmt = null;
        ResultSet rs = null;
        boolean success = true;

            try {
                GlobalStuff.getDBConnection().setAutoCommit(false);
                String sql ="SET SQL_SAFE_UPDATES=0;"
                        +"DELETE FROM t_dependant "
                        +"WHERE pk_dependant in ("
                        +"SELECT * FROM "
                        +"(SELECT pk_dependant from t_dependant WHERE fk_master = " + pk_master_to_delete
                        +") subquery); "
                        +"DELETE FROM t_master WHERE pk_master = " + pk_master_to_delete;
                prestmt = GlobalStuff.getDBConnection().prepareStatement(sql);
                rs = prestmt.executeQuery();
            }catch...

0 Answers0