任何人都可以向我解释一下,为什么这个mysql脚本可以在我的Mysql Workbench上工作,而不是在我的tomcat服务器上?
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:您的SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在'DELETE FROM t_dependant WHERE pk_dependant'(SELECT * FROM(SELECT pk_dependant a'at line 1
)附近使用正确的语法
编辑:
这是我在tomcat服务器上运行的代码:
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...