posts - 5,  comments - 0,  trackbacks - 0
今天在用IBATIS帮别人写个程序的时候突然出现了一个很怪异的错误
com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in ./map/Guest.xml.  
--- The error occurred while applying a result map.  
--- Check the Guest.listGuest.  
--- Check the result mapping for the 'password' property.  
--- Cause: java.sql.SQLException: Column 'userpwd' not found.


at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:94)
at com.zhxingchen.guestbook.dao.impl.BaseDAOImpl.queryAll(BaseDAOImpl.java:36)
at com.zhxingchen.guestbook.dao.impl.GuestDAOImpl.queryGuestByProperty(GuestDAOImpl.java:68)
at com.zhxingchen.guestbook.dao.impl.TestGuestDAO.testQueryByProperty(TestGuestDAO.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.SQLException: Column 'userpwd' not found.


at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:983)
at com.mysql.jdbc.ResultSet.getString(ResultSet.java:4826)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.ibatis.common.jdbc.logging.ResultSetLogProxy.invoke(ResultSetLogProxy.java:47)
at $Proxy7.getString(Unknown Source)
at com.ibatis.sqlmap.engine.type.StringTypeHandler.getResult(StringTypeHandler.java:35)
at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getPrimitiveResultMappingValue(ResultMap.java:619)
at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:345)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
... 28 more
    出现这个错误的当头我就懵了,我怎么也想不明白数据库里面怎么会没有userpwd这个字段,我反复的对照都感觉数据库里是有的啊,最后终于让我找出了问题所在,等知道后我就晕了,一个很简单的映射错误,我居然反复了看了3个小时,可能是熬夜了思维停滞了吧!
以下是SQLMap.xml的两段段代码:第一段是定义了一个resultMap,第二段是利用这个resultMap返回
<resultMap id="listGuest" class="guest"> <result property="id"/> <result property="userName"/> <result property="password" column="userpwd"/> <result property="realName"/> <result property="gender"/> <result property="age"/> <result property="email"/> <result property="qq"/> </resultMap>
<statement id="queryGuestByProperty" parameterClass="guest" resultMap="listGuest"> SELECT ID as id, USERNAME as userName, USERPWD as password, USERREALNAME as realName, USERSSEX as gender, USERAGE as age, USEREMAIL as email, USERQQ as qq FROM GUEST <dynamic prepend="WHERE"> <isNotNull prepend="AND" property="password"> USERNAME=#userName# </isNotNull>
...............
也许不仔细看还真看不出来,其实USERPWD在取出来的时候就已经转换成password了,难怪在resultMap中始终找不到userpwd,这样要是能找到才怪!~
改的话很容易,我倾向于改resultMap文件,将password后面的 column="userpwd"去掉就OK了!~
万事还得谨慎!!!!!
posted on 2010-05-15 06:57 Zhjiang 阅读(998) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 
<2010年5月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(1)

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜