首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

SqlServer 2005 ibatis配置文件sql失误

2012-10-21 
SqlServer 2005 ibatis配置文件sql出错报错的ibatis xml文件b部分SQL codeselect idgetTabTmsparamete

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文件的时候,是怎么拼接查询条件的?这sqlserver 2005在ibatis中处处透露着诡异- - 就好像上面sql中的 top 后面居然不能直接用##传值,而要用$$

[解决办法]
把sql打印出来,然后执行下,看哪里错了
[解决办法]
指出的是ibatis中用sql2005也能用#的,然后呢ibatis的配置文件中能直接用<>吗?我之前一直用的是lt;gt; 上面都是我的拙见,如果说错了别喷哈。O(∩_∩)O哈哈~。。。。。。。。。。
[解决办法]
你把SQL放到SqlServer工具里执行一下,能成功不?


[解决办法]
看看你传入的参数有没有问题,包括参数的类型什么的
[解决办法]
$minSize$
改为
#minSize#

还有下面的

热点排行