Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > ibatis JshopStore5的sqlmap的xml错误,NestedSQLException错误
【标  题】:ibatis JshopStore5的sqlmap的xml错误,NestedSQLException错误
【关键字】:ibatis,JshopStore5,sqlmap,xml,NestedSQLException
【来  源】:http://www.blogjava.net/mintqzy/archive/2007/01/16/94203.html

ibatis JshopStore5的sqlmap的xml错误,NestedSQLException错误

Your Ad Here 今天在继续研究JShopStore时候,在查看product的明细时即
执行action
????<action?path="/shop/viewItem"?type="org.apache.struts.beanaction.BeanAction"
????????????name
="catalogBean"?scope="session"
????????????validate
="false"?input="/catalog/Product.jsp">
??????
<forward?name="success"?path="/catalog/Item.jsp"/>
????
</action>
报NestedSqlException错误,错误的核心部分如下:
Caused?by:?com.ibatis.dao.client.DaoException:?Failed?to?execute?queryForObject?-?id?[getItem],?parameterObject?[EST-18].??Cause:?com.ibatis.common.jdbc.exception.NestedSQLException:???
---?The?error?occurred?in?com/ibatis/jpetstore/persistence/sqlmapdao/sql/Item.xml.??
---?The?error?occurred?while?applying?a?parameter?map.??
---?Check?the?getItem-InlineParameterMap.??
---?Check?the?statement?(query?failed).??
---?Cause:?java.sql.SQLException:?[Microsoft][SQLServer?2000?Driver?for?JDBC][SQLServer]???'itemid'?????
Caused?by:?java.sql.SQLException:?[Microsoft][SQLServer?
2000?Driver?for?JDBC][SQLServer]???'itemid'?????
Caused?by:?com.ibatis.common.jdbc.exception.NestedSQLException:???
---?The?error?occurred?in?com/ibatis/jpetstore/persistence/sqlmapdao/sql/Item.xml.??
---?The?error?occurred?while?applying?a?parameter?map.??
---?Check?the?getItem-InlineParameterMap.??
---?Check?the?statement?(query?failed).??
---?Cause:?java.sql.SQLException:?[Microsoft][SQLServer?2000?Driver?for?JDBC][SQLServer]???'itemid'?????
我跟踪、跟踪,跟踪到ItemSqlMapDao
??public?Item?getItem(String?itemId)?{
????Integer?i?
=?(Integer)?queryForObject("getInventoryQuantity",?itemId);
????Item?item?
=?(Item)?queryForObject("getItem",?itemId);
????item.setQuantity(i.intValue());
????
return?item;
??}
找到错误语句
Item item = (Item) queryForObject("getItem", itemId);
继续跟踪到操纵的sql_map文件Item.xml
<select?id="getItem"?resultClass="item"?parameterClass="string"?cacheModel="quantityCache">
????select
??????ITEMID,
??????LISTPRICE,
??????UNITCOST,
??????SUPPLIER?AS?supplierId,
??????I.PRODUCTID?AS?"product.productId",
??????NAME?AS?"product.name",
??????DESCN?AS?"product.description",
??????CATEGORY?AS?"product.categoryId",
??????STATUS,
??????ATTR1?AS?attribute1,
??????ATTR2?AS?attribute2,
??????ATTR3?AS?attribute3,
??????ATTR4?AS?attribute4,
??????ATTR5?AS?attribute5,
??????QTY?AS?quantity
????from?ITEM?I,?INVENTORY?V,?PRODUCT?P
????where?P.PRODUCTID?=?I.PRODUCTID
??????and?I.ITEMID?=?V.ITEMID
??????and?I.ITEMID?=?#value#
??
</select>
问题就出现在这,Item类中包含了Product类,出现NestedSqlException错误。
查阅了ibatis帮助,此处sql_map的嵌套类写法是正确的。我又将这个sql语句拷贝到MsSqlServer中执行,结果也是正确的。陷入困惑。
在网上找资料,发现了一个英文网站中指明了
---?Cause:?java.sql.SQLException:?[DataDirect][SQLServer?JDBC?Driver][SQLServer]Ambiguous?column?name?'itemid'.?
哈哈,问题就此找到了。即itemid列指待不清,应该将ITEMID替换成I.ITEMID AS ITEMID。而之所以我直接将语句拷贝到MsSqlServer执行正确,是因为MSSqlServer自动做了处理,加上了表的别名。而这个Sql语句本身是存在问题的。
所以item.xml替换后的代码为
??<select?id="getItem"?resultClass="item"?parameterClass="string"?cacheModel="quantityCache">
????select
??????I.ITEMID?AS?ITEMID,
??????LISTPRICE,
??????UNITCOST,
??????SUPPLIER?AS?supplierId,
??????I.PRODUCTID?AS?"product.productId",
??????NAME?AS?"product.name",
??????DESCN?AS?"product.description",
??????CATEGORY?AS?"product.categoryId",
??????STATUS,
??????ATTR1?AS?attribute1,
??????ATTR2?AS?attribute2,
??????ATTR3?AS?attribute3,
??????ATTR4?AS?attribute4,
??????ATTR5?AS?attribute5,
??????QTY?AS?quantity
????from?ITEM?I,?INVENTORY?V,?PRODUCT?P
????where?P.PRODUCTID?=?I.PRODUCTID
??????and?I.ITEMID?=?V.ITEMID
??????and?I.ITEMID?=?#value#
??
</select>
问题解决,OK!诶,乱码也耽误了一些时间,否则早就解决了,看来乱码误事啊!
学习Java6(六) 嵌入式数据库Derby(1)简介:【上一篇】
[Plugin]·Eclipse中的Resource - 2:【下一篇】
【相关文章】
  • ibatis 对象关系实现
  • xml内容显示的4种方法
  • ibatis 开始之旅
  • iBatis的JpetStore示例中MVC机制实现的研究,BeanAction,BaseBean
  • 有时候看.neter的表现,真的很奇怪。那种近在眼前而不见的茫然,真的让你为之着急——说说XML的无效字符
  • 闲话XML+XSLT的新用途:特殊界面处理方案……(主要应用于C/S模式)
  • XML基础知识
  • 今天遇见的一个问题xml格式的字符串,有办法直接的解析吗
  • c#读写xml文件
  • webwork2.2.4+ibatis2.2+lucene+spring+velocity 编写的bt服务器(提供源代码)
  • 【随机文章】
  • 搞定emacs的make-header
  • JAVA上加密算法的实现用例
  • 陈建斌自爆与初恋情人呼小静的情史
  • 实验8 I/O流
  • stl 函数对象
  • 消灭内存的隐形杀手(2)
  • Before main() 分析
  • 数据库记录按指定顺序排序
  • Javascript实例教程(20) OLE Automation(7)
  • VC中访问Access数据库的方法(不需要用户建立ODBC数据源)
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.