我用 Struts + spring + ibatis 做了一个页面,报了下面的错,org.springframework.jdbc.BadSqlGrammarException: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in net/szpt/ei/obs/domain/feedBackVo.xml.
--- The error occurred while applying a result map.
--- Check the feedBackVo.feedBackVoResult.
--- Check the result mapping for the 'userId' property.
--- Cause: java.sql.SQLException: Column 'userId' not found.feedBackVo.xml 原码<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="feedBackVo">
<typeAlias alias="feedBackVo" type="net.szpt.ei.obs.vo.FeedBackVo"/>
<resultMap class="feedBackVo" id="feedBackVoResult">
<result property="feedBackId" column="feedBackId"/>
<result property="userId" column="userId"/>
<result property="userName" column="userName"/>
<result property="title" column="title"/>
<result property="content" column="content"/>
<result property="status" column="status"/>
<result property="date" column="date"/>
</resultMap> <select id="queryFeedBack" parameterClass="feedBackVo" resultMap="feedBackVoResult">
SELECT f.feedBackId, u.userName, f.title, f.status
FROM feedback f, t_user u
WHERE f.userId = u.userId
<dynamic prepend=" ">
<isNotEmpty property="feedBackId" prepend=" AND ">feedBackId = #feedBackId#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">userName = #userName#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">title = #title#</isNotEmpty>
<isNotEmpty property="status" prepend=" AND ">status = #status#</isNotEmpty>
</dynamic>
</select>
<select id="queryFeedBackContent" parameterClass="java.lang.Integer" resultMap="feedBackVoResult">
SELECT *
FROM feedback f, t_user u
WHERE f.userId = u.userId
AND feedBackId = #feedBackId#
</select></sqlMap> 问题是出在 第一个 select 的SELECT f.feedBackId, u.userName, f.title, f.status
如果换成 select * 就没错了请问下这个问题怎么解决
--- The error occurred in net/szpt/ei/obs/domain/feedBackVo.xml.
--- The error occurred while applying a result map.
--- Check the feedBackVo.feedBackVoResult.
--- Check the result mapping for the 'userId' property.
--- Cause: java.sql.SQLException: Column 'userId' not found.feedBackVo.xml 原码<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="feedBackVo">
<typeAlias alias="feedBackVo" type="net.szpt.ei.obs.vo.FeedBackVo"/>
<resultMap class="feedBackVo" id="feedBackVoResult">
<result property="feedBackId" column="feedBackId"/>
<result property="userId" column="userId"/>
<result property="userName" column="userName"/>
<result property="title" column="title"/>
<result property="content" column="content"/>
<result property="status" column="status"/>
<result property="date" column="date"/>
</resultMap> <select id="queryFeedBack" parameterClass="feedBackVo" resultMap="feedBackVoResult">
SELECT f.feedBackId, u.userName, f.title, f.status
FROM feedback f, t_user u
WHERE f.userId = u.userId
<dynamic prepend=" ">
<isNotEmpty property="feedBackId" prepend=" AND ">feedBackId = #feedBackId#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">userName = #userName#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">title = #title#</isNotEmpty>
<isNotEmpty property="status" prepend=" AND ">status = #status#</isNotEmpty>
</dynamic>
</select>
<select id="queryFeedBackContent" parameterClass="java.lang.Integer" resultMap="feedBackVoResult">
SELECT *
FROM feedback f, t_user u
WHERE f.userId = u.userId
AND feedBackId = #feedBackId#
</select></sqlMap> 问题是出在 第一个 select 的SELECT f.feedBackId, u.userName, f.title, f.status
如果换成 select * 就没错了请问下这个问题怎么解决
解决方案 »
- 控制打印机输出指定格式的内容和图片
- Sun Java 5+ Eclipse 3.2 +MyEclipse 5.0.0. 开发web service报org.codehaus.xfire.XFireRuntimeException: Couldn't parse stream
- tomcat 修改server.xml 不重启服务器
- 我 想问大哥哥们,我现在有九十万条数据,在分页是LIST 读不出来了,想求一个更好的分页数据,现求代码,谢谢
- HTTP Status 500
- jboss负载均衡算法中的family概念??
- 跪求jspsmart包!!!!!!
- 谁知道杰贝尔电子(广州)有限公司这个公司?
- 如何设置JTable选中的某一行为不可编辑状态?
- 求教wml中用post方式传递参数乱码问题
- 求用java实现类似QQ登录页面的布局的方法
- java.lang.OutOfMemoryError: Java heap space
SELECT f.feedBackId, u.userId, u.userName, f.title, f.status , f.content, f.date
u.userName,
f.title,
f.status
FROM
....
没有全角半角引起的问题吗? 试试我这个先。 再看看情况
<dynamic prepend=" ">
<isNotEmpty property="feedBackId" prepend=" AND ">feedBackId = #feedBackId#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">userName = #userName#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">title = #title#</isNotEmpty>
<isNotEmpty property="status" prepend=" AND ">status = #status#</isNotEmpty>
</dynamic>
<isNotEmpty property="feedBackId" prepend=" AND ">feedBackId = #feedBackId#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">userName = #userName#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">title = #title#</isNotEmpty>
<isNotEmpty property="status" prepend=" AND ">status = #status#</isNotEmpty>
</dynamic>
两个表的字段有重名吗?
select *
都不会报错。也就是说,如果 resultMap 里定义的这些字段,如果有任何一个字段没有查询,就会报错但我这里只需要查询其中的某几个字段就可以了,这种情况要怎么解决
<result property="feedBackId" column="feedBackId"/>
<result property="userId" column="userId"/>
<result property="userName" column="userName"/>
<result property="title" column="title"/>
<result property="content" column="content"/>
<result property="status" column="status"/>
<result property="date" column="date"/>
</resultMap>而在查询的语句中只返回了 4个字段 上面的红色字段没有返回,映射不能一一对应,这个必须一一对应 <select id="queryFeedBack" parameterClass="feedBackVo" resultMap="feedBackVoResult">
SELECT f.feedBackId, u.userName, f.title, f.status
FROM feedback f, t_user u
WHERE f.userId = u.userId
<dynamic prepend=" ">
<isNotEmpty property="feedBackId" prepend=" AND ">feedBackId = #feedBackId#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">userName = #userName#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">title = #title#</isNotEmpty>
<isNotEmpty property="status" prepend=" AND ">status = #status#</isNotEmpty>
</dynamic>
</select>
重新定义一个 <resultMap class="feedBackVo" id="feedBackVoResult1">
<result property="feedBackId" column="feedBackId"/>
<result property="userName" column="userName"/>
<result property="title" column="title"/>
<result property="status" column="status"/>
</resultMap>然后在 <select id="queryFeedBack" parameterClass="feedBackVo" resultMap="feedBackVoResult1">resultMap 可以根据自己的需要定义多个
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="feedBackVo">
<typeAlias alias="feedBackVo" type="net.szpt.ei.obs.vo.FeedBackVo"/>
<resultMap class="feedBackVo" id="feedBackVoResult">
<result property="feedBackId" column="feedBackId"/>
<result property="userId" column="userId"/>
<result property="userName" column="userName"/>
<result property="title" column="title"/>
<result property="content" column="content"/>
<result property="status" column="status"/>
<result property="date" column="date"/>
</resultMap>
<resultMap class="feedBackVo" id="feedBackVoResult1">
<result property="feedBackId" column="feedBackId"/>
<result property="userName" column="userName"/>
<result property="title" column="title"/>
<result property="status" column="status"/>
</resultMap> <select id="queryFeedBack" parameterClass="feedBackVo" resultMap="feedBackVoResult1">
SELECT f.feedBackId, u.userName, f.title, f.status
FROM feedback f, t_user u
WHERE f.userId = u.userId
<dynamic prepend=" ">
<isNotEmpty property="feedBackId" prepend=" AND ">feedBackId = #feedBackId#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">userName = #userName#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">title = #title#</isNotEmpty>
<isNotEmpty property="status" prepend=" AND ">status = #status#</isNotEmpty>
</dynamic>
</select>
<select id="queryFeedBackContent" parameterClass="java.lang.Integer" resultMap="feedBackVoResult">
SELECT *
FROM feedback f, t_user u
WHERE f.userId = u.userId
AND feedBackId = #feedBackId#
</select></sqlMap>
这样就可以了
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="feedBackVo">
<typeAlias alias="feedBackVo" type="net.szpt.ei.obs.vo.FeedBackVo"/>
<resultMap class="feedBackVo" id="feedBackVoResult">
<result property="feedBackId" column="feedBackId"/>
<result property="userId" column="userId"/>
<result property="userName" column="userName"/>
<result property="title" column="title"/>
<result property="content" column="content"/>
<result property="status" column="status"/>
<result property="date" column="date"/>
</resultMap>
<resultMap class="feedBackVo" id="feedBackVoResult1">
<result property="feedBackId" column="feedBackId"/>
<result property="userName" column="userName"/>
<result property="title" column="title"/>
<result property="status" column="status"/>
</resultMap> <select id="queryFeedBack" parameterClass="feedBackVo" resultMap="feedBackVoResult1">
SELECT f.feedBackId, u.userName, f.title, f.status
FROM feedback f, t_user u
WHERE f.userId = u.userId
<dynamic prepend=" ">
<isNotEmpty property="feedBackId" prepend=" AND ">feedBackId = #feedBackId#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">userName = #userName#</isNotEmpty>
<isNotEmpty property="userId" prepend=" AND ">title = #title#</isNotEmpty>
<isNotEmpty property="status" prepend=" AND ">status = #status#</isNotEmpty>
</dynamic>
</select>
<select id="queryFeedBackContent" parameterClass="java.lang.Integer" resultMap="feedBackVoResult">
SELECT *
FROM feedback f, t_user u
WHERE f.userId = u.userId
AND feedBackId = #feedBackId#
</select></sqlMap>