ibatis执行多条sql?

amss 发布于 2014/01/14 17:26
阅读 3K+
收藏 0

ibatis怎么配置 执行多条sql

类似这个意思:

<delete  id="deleteRelatedDatas" parameterClass="java.lang.Long">
        delete from t_table_1 t1 where t1.user_id=#value#;
        delete from t_table_2 t2 where t2.user_id=#value#;
        delete from t_table_3 t3 where t3.user_id=#value#;
</delete>

错误:

{conn-100593} Preparing Statement:    delete from t_table_1 t1 where t1.user_id=?;   delete from t_table_2 t2 where t2.user_id=?;   delete from t_table_3 t3 where t3.user_id=?;  
Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/xxx/pojo/xml/Xxxx.xml.  
--- The error occurred while applying a parameter map.  
--- Check the com.xxxx.pojo.Xxxxx.deleteRelatedDatas-InlineParameterMap.  
--- Check the statement (update failed).  
--- 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 't1 where t1.user_id=99;   delete from t_table_2 t2 where t2.user_id=99;   delete' at line 1
org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/xxxx/pojo/xml/Xxxxx.xml.  
--- The error occurred while applying a parameter map.  
--- Check the com.xxxx.pojo.Xxxx.deleteRelatedDatas-InlineParameterMap.  
--- Check the statement (update failed).  
--- 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 't1 where t1.user_id=99;   delete from t_table_2 t2 where t2.user_id=99;   delete' at line 1
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:203)


加载中
0
pantrick
pantrick
看你用哪种数据库,我用mysql 只要url后面加 allowMultiQueries 就可以了
a
amss
回复 @抓瓦工人 : 那个参数可以,应该是我代码的问题,谢了
pantrick
pantrick
回复 @motm127 : 我用的是mybatis最新版,有区别吗?
a
amss
回复 @抓瓦工人 : 直接发到问题里了,分号的错,好像不支持这么写,你也用的ibatis?
pantrick
pantrick
回复 @motm127 : 报错发上来!
a
amss
貌似不行,jdbc:mysql://localhost:3306/dbss?allowMultiQueries=true,还是报错
0
liuxin
liuxin
where col in(id1,id2,id3)
0
lock_free
lock_free
batch update 试试。
0
南湖船老大
南湖船老大

引用来自“抓瓦工人”的答案

看你用哪种数据库,我用mysql 只要url后面加 allowMultiQueries 就可以了
+1 这样JDBC就会自动以分号来隔开每一条SQL
南湖船老大
南湖船老大
回复 @motm127 : 那可能ibatis又做了什么手脚吧
a
amss
貌似不行,jdbc:mysql://localhost:3306/dbss?allowMultiQueries=true,还是会报错
返回顶部
顶部