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 项包含了一个变量,该变量位于标识列位置的表达式中。只有排序依据表达式引用的是列名时,才允许在该表达式中使用变量。
<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 项包含了一个变量,该变量位于标识列位置的表达式中。只有排序依据表达式引用的是列名时,才允许在该表达式中使用变量。
首先, <![CDATA[ 这个东西在每个sql用一次足矣,它的作用lz可以查一下,没记错的话应该是跟大于小于号有关的东西
<dynamic prepend="and"> 还有这个,只提供了个关联符,完全可以换种方式,它在这只能添乱,
<dynamic prepend="and">
<isNotEmpty prepend="and" property="a.status">
这两个一块用,可能是有问题的,两次提供了连接符and
a.status in #status# ]]> ,<isNotEmpty prepend="and" property="a.status">
这个,lz既然是通过HashMap传的参数,那么#status#中间和property="a.status"中的东西因该是HashMap对应的Key键,应该是一个
parameterClass="java.util.Map"
Map没用过,不过最好用HashMap,这样操作起来会简单
## 会自动加上''