0

I want to execute multiple queries in jdbc. But i got below error. I don't know why its throw like this. Please anyone help to fix.

My code:

Statement chkUserStmt = DataAccess.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

String fkcheck = "SET FOREIGN_KEY_CHECKS=0";
            String query   = "DELETE FROM USERS,ACCOUNT,ADDRESS,USEREMPLOYER,VEHICLE,USERVEHICLE "
                            +"USING USERS,ACCOUNT,ADDRESS,USEREMPLOYER,VEHICLE,USERVEHICLE"
                            +"WHERE USERS.MOBILE = ACCOUNT.MOBILE "
                            +"AND"
                            +"ADDRESS.MOBILE = USERS.MOBILE"
                            +"AND"
                            +"USEREMPLOYER.MOBILE = USERS.MOBILE"
                            +"AND"
                            +"VEHICLE.CREATEDBY = USERS.MOBILE"
                            +"AND"
                            +"USERVEHICLE.MOBILE = USERS.MOBILE"
                            +"AND"
                            +"USERS.MOBILE ='" + mobile + "'"; 
            String fkchecks = "SET FOREIGN_KEY_CHECKS=1";

            DataAccess.conn.setAutoCommit(false);
            chkUserStmt.addBatch(fkcheck);
            chkUserStmt.addBatch(query);
            chkUserStmt.addBatch(fkchecks);

            chkUserStmt.executeBatch();
            DataAccess.conn.commit();

My error:

Exception in thread "main" java.sql.BatchUpdateException: Not unique table/alias: 'USERS'
    at com.mysql.jdbc.Statement.executeBatch(Statement.java:961)
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Abdul
  • 11
  • 5
  • Are you trying to do a JOIN delete without using the JOIN keyword? – Tapani Feb 18 '16 at 07:40
  • No, I wont trying to join delete – Abdul Feb 18 '16 at 07:42
  • If you want to delete from several tables with one query then you have to use JOIN. See http://stackoverflow.com/questions/1233451/delete-from-two-tables-in-one-query. – Tapani Feb 18 '16 at 07:50
  • I tried that also gave same error – Abdul Feb 18 '16 at 07:54
  • As shown, you're using `USING` incorrectly, and you shouldn't be using `USING` at all. The syntax you are attempting is so incorrect that the error message is actually inaccurate, because the server is not actually understanding your intentions. Rather than saying "I tried that also," please show us your rewritten query with explicit `JOIN ... ON` syntax, and correct multi table delete syntax (`DELETE t1, t2, t3 FROM table1 t1 JOIN table t2 ON t2.col1 = t1.col2 JOIN ... WHERE ...`) then post the query and result. – Michael - sqlbot Feb 19 '16 at 00:16

0 Answers0