ibatis的sqlmap不太会写,帮忙看一下这个错误. 写order by 子句用变量处理出错
sqlmap 语句:
<select id="schedule_getScheduleAll" resultClass="java.util.HashMap" parameterClass="java.util.Map">
<![CDATA[
select a.*,b.dept_name as center_dept from tb_schedule a left join tb_dept b on a.center_dept_sn=b.sn
where a.center_dept_sn=#center_dept_sn#
]]>
<dynamic prepend="and">
<isNotEmpty prepend="and" property="a.status">
<![CDATA[ a.status in #status# ]]>
</isNotEmpty>
</dynamic>
<![CDATA[
order by #search_order# desc
]]>
</select>
java action语句:
HashMap map = new HashMap();
map.put("center_dept_sn", "dwdefe234769222");
map.put("search_status", "0,1");
map.put("search_order", "a.create_datetime");
List list0 = (List)this.getScheduleService().getScheduleAll(map);
提示出错:
2009-03-10 09:30:19,968 INFO [org.springframework.jdbc.support.SQLErrorCodesFactory] - SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
2009-03-10 09:30:19,984 WARN [org.apache.struts.action.RequestProcessor] - Unhandled Exception thrown: class org.springframework.jdbc.UncategorizedSQLException
2009-03-10 09:30:19,984 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/blmis].[action]] - Servlet.service() for servlet action threw exception
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation: encountered SQLException [
--- The error occurred while applying a parameter map.
--- Check the schedule_getScheduleAll-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: ORDER BY 子句所标识的第 1 个 SELECT 项包含了一个变量,该变量位于标识列位置的表达式中。只有排序依据表达式引用的是列名时,才允许在该表达式中使用变量。]; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the schedule_getScheduleAll-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: ORDER BY 子句所标识的第 1 个 SELECT 项包含了一个变量,该变量位于标识列位置的表达式中。只有排序依据表达式引用的是列名时,才允许在该表达式中使用变量。
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the schedule_getScheduleAll-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: ORDER BY 子句所标识的第 1 个 SELECT 项包含了一个变量,该变量位于标识列位置的表达式中。只有排序依据表达式引用的是列名时,才允许在该表达式中使用变量。
Caused by: java.sql.SQLException: ORDER BY 子句所标识的第 1 个 SELECT 项包含了一个变量,该变量位于标识列位置的表达式中。只有排序依据表达式引用的是列名时,才允许在该表达式中使用变量。