ibatis2的问题,请高手指点.
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the User.getUser-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE) for operation 'like'
Caused by: java.sql.SQLException: Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE) for operation 'like'
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:185)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:123)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:610)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:584)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:101)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:78)
at test.Test.getUser(Test.java:143)
at test.Test.main(Test.java:203)
Caused by: java.sql.SQLException: Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE) for operation 'like'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1124)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:676)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:773)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:180)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
... 7 more
/************************************************************/配置
<select id="getUser" resultMap="userResult" parameterClass="java.util.HashMap">
<![CDATA[
select
id,
name,
date
from t_user
]]>
<dynamic prepend="WHERE">
<isNotNull prepend="AND" property="id">(id like #id#)</isNotNull>
<isNotNull prepend="AND" property="name">(name like #name#)</isNotNull>
</dynamic>
</select>
/********************************************************************/
public static List getUser() {
SqlMapClient sqlMap = getSqlMapClient();
List user = null;
try {
sqlMap.startTransaction();
HashMap params = new HashMap();
params.put("name", "%test%");
//User t = new User();
//t.setName("liulu");
user = sqlMap.queryForList("User.getUser",params );
sqlMap.commitTransaction();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
sqlMap.endTransaction();
} catch (SQLException e) {
e.printStackTrace();
}
}
return user;
}
/***********************************************/