日期:2014-05-19  浏览次数:20760 次

SqlServer 2005 ibatis配置文件sql出错
报错的ibatis xml文件b部分
SQL code
<select id="getTabTms"  parameterClass="selectObj"  resultClass="tab_Tms">
     <![CDATA[ 
         select top $minSize$
             shopNo,
            name,
            rank,
            supplyShop,
            brand
         from (select * from etam_tms_address where  flag is NULL or flag <> 4) a 
         where 
         shopNo+'_'+brand not in(
                 select top $maxSize$ shopNo+'_'+brand from etam_tms_address 
                 where flag is NULL or flag <> 4 
         ) 
        ]]>   
    </select>    



Exception in thread "timerFactory" org.springframework.jdbc.BadSqlGrammarExcepti
on: SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.c
ommon.jdbc.exception.NestedSQLException:
--- The error occurred in com/zhitengda/valueobject/sqlmap/Tab_hr_tms.xml.
--- The error occurred while applying a parameter map.
--- Check the getTabTms-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.microsoft.sqlserver.jdbc.SQLServerException: '-' 附近有语法错误。

Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/zhitengda/valueobject/sqlmap/Tab_hr_tms.xml.
--- The error occurred while applying a parameter map.
--- Check the getTabTms-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: com.microsoft.sqlserver.jdbc.SQLServerException: '-' 附近有语法错误。

  at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQu
eryWithCallback(GeneralStatement.java:185)
  at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQu
eryForList(GeneralStatement.java:123)
  at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(Sql
MapExecutorDelegate.java:615)
  at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(Sql
MapExecutorDelegate.java:589)
  at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSe
ssionImpl.java:118)
  at org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClien
t(SqlMapClientTemplate.java:268)
  at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapCli
entTemplate.java:193)
  at org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListRe
sult(SqlMapClientTemplate.java:219)
  at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlM
apClientTemplate.java:266)
  at com.zhitengda.services.dao.TabHrTmsDao.getTabTmsList(TabHrTmsDao.java
:25)
  at com.zhitengda.services.TabHrTmsServiceImpl.getTabTmsList(TabHrTmsServ
iceImpl.java:28)
  at com.zhitengda.jbos.TabTmsJobs.run(TabTmsJobs.java:34)
  at java.util.TimerThread.mainLoop(Timer.java:512)
  at java.util.TimerThread.run(Timer.java:462)

我已经搜索文档,根本就没有含有'-'字符的句子,还有一个跟着个<SELECT>一样<SELECT>,因为不是联合主键,所以没shopNo+'_'+brand not in 而是直接 id not in ,那个<SELECT>执行没有问题。所以我认为问题出在sqlserver 2005的jdbc驱动解析这个拼接字符上,因为一直用的oracle,不知道sqlserver 2005在配置ibatis文件的时候,是怎么拼接查询条件的