日期:2014-05-20  浏览次数:20841 次

ibatis入门级问题
The error occurred while applying a result map. <-!!!!!!!!!!!!!!!!!!!!就是这个 

如上所示,说是Result配制的有问题
可是我觉得我配置的没错呀~

我急了,就把ibatis自带的例子运行粘到工程里运行了一下,结果是:错误一样

com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in com/mydomain/data/Account.xml.  
--- The error occurred while applying a result map.  
--- Check the Account.AccountResult.  
--- The error happened while setting a property on the result object. 

没招了~


30分钟前刚下的ibatis最新的包,运行的里面自带的例子http://ibatis.apache.org/javadownloads.cgi

代码也剪贴上来:
<resultMap id="AccountResult" class="Account">
  <result property="id" column="ACC_ID"/>
  <result property="firstName" column="ACC_FIRST_NAME"/>
  <result property="lastName" column="ACC_LAST_NAME"/>
  <result property="emailAddress" column="ACC_EMAIL"/>
  </resultMap>

  <!-- Select with no parameters using the result map for Account class. -->
  <select id="selectAllAccounts" resultMap="AccountResult">
  select * from ACCOUNT
  </select>


SQLserver2K的数据库表
CREATE TABLE [ACCOUNT] (
[ACC_ID] [int] NULL ,
[ACC_FIRST_NAME] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[ACC_LAST_NAME] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[ACC_EMAIL] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

郁闷呀
郁闷呀
郁闷呀
郁闷呀

网上也搜不到相应的解决方法


------解决方案--------------------
在你的url后面加上 SelectMethod=cursor

jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=xxx;SelectMethod=Cursor;
------解决方案--------------------
这个原因是 再一个connection中使用了多个statement或者preparestatement等,sqlserver2000默认在一个连接中只能使用一个statement

sqlserver默认是SelectMethod=direct(默认方式),这种只支持一个连接打开一个statement,如果这样
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=xxx;SelectMethod=cursor;

这样设置之后就支持打开多个了,注意cursor似乎区分大小,是小写的