当前位置: 代码迷 >> J2EE >> Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
  详细解决方案

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:

热度:601   发布时间:2016-04-22 03:03:58.0
Ibatis 的 delete 问题!!!
Ibatis 已经配置好了。

我现在想要实现的功能是:

动态切换数据库,然后执行删除语句。

如下:

我在 User.xml 中

<delete id="del">use $database$; delete from t_order where id =#id#;</delete>

配置一个删除的语句

在类中 调用

paramMap.put("id", id);
paramMap.put("database", "test");
client.delete("delUsers", paramMap);


报的错误是 :

com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in com/beans/Users.xml.  
--- The error occurred while applying a parameter map.  
--- Check the delUsers-InlineParameterMap.  
--- Check the statement (update failed).  
[color=red]--- Cause: 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 tbl_tt where id = 6' at line 1[/color]
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:91)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.update(SqlMapExecutorDelegate.java:505)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.delete(SqlMapExecutorDelegate.java:528)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.delete(SqlMapSessionImpl.java:98)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.delete(SqlMapClientImpl.java:75)
at com.service.impl.UserServiceImpl.executeDelUsers(UserServiceImpl.java:103)
at com.test.Test.doDelUsers(Test.java:26)
at com.test.Test.main(Test.java:22)
[color=red]Caused by: 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 tbl_tt where id = 6' at line 1[/color]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:403)
at com.mysql.jdbc.Util.getInstance(Util.java:378)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1031)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3361)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3295)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1852)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1975)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2476)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1583)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:988)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:81)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUpdate(GeneralStatement.java:200)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:78)
... 7 more


求高手指教!

------解决方案--------------------
不能这样写啊,大哥
------解决方案--------------------
如果用到两个数据库的话 你需要配置两个数据源 <delete></delete>里面只能是delete语句
  相关解决方案