posts - 11,  comments - 28,  trackbacks - 0
          今天在繼續(xù)研究JShopStore時(shí)候,在查看product的明細(xì)時(shí)即
          執(zhí)行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>
          報(bào)NestedSqlException錯(cuò)誤,錯(cuò)誤的核心部分如下:
          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;
          ??}
          找到錯(cuò)誤語句
          Item item = (Item) queryForObject("getItem", itemId);
          繼續(xù)跟蹤到操縱的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>
          問題就出現(xiàn)在這,Item類中包含了Product類,出現(xiàn)NestedSqlException錯(cuò)誤。
          查閱了ibatis幫助,此處sql_map的嵌套類寫法是正確的。我又將這個(gè)sql語句拷貝到MsSqlServer中執(zhí)行,結(jié)果也是正確的。陷入困惑。
          在網(wǎng)上找資料,發(fā)現(xiàn)了一個(gè)英文網(wǎng)站中指明了
          ---?Cause:?java.sql.SQLException:?[DataDirect][SQLServer?JDBC?Driver][SQLServer]Ambiguous?column?name?'itemid'.?
          哈哈,問題就此找到了。即itemid列指待不清,應(yīng)該將ITEMID替換成I.ITEMID AS ITEMID。而之所以我直接將語句拷貝到MsSqlServer執(zhí)行正確,是因?yàn)镸SSqlServer自動(dòng)做了處理,加上了表的別名。而這個(gè)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!誒,亂碼也耽誤了一些時(shí)間,否則早就解決了,看來亂碼誤事啊!
          posted on 2007-01-16 13:38 滌生 閱讀(3368) 評(píng)論(6)  編輯  收藏


          FeedBack:
          # re: ibatis JshopStore5的sqlmap的xml錯(cuò)誤,NestedSQLException錯(cuò)誤[未登錄]
          2007-01-16 17:06 | junmy
          posted on 2006-05-22 00:42
          http://www.aygfsteel.com/wujun/archive/2006/05/22/47392.html
          早就發(fā)現(xiàn)了~
            回復(fù)  更多評(píng)論
            
          # re: ibatis JshopStore5的sqlmap的xml錯(cuò)誤,NestedSQLException錯(cuò)誤
          2007-01-16 20:21 | 滌生
          @junmy
          今天我還在blogjava上找了一圈,沒找到對(duì)應(yīng)的。要是早看到你的大作,可以省我半個(gè)上午的時(shí)間  回復(fù)  更多評(píng)論
            
          # re: ibatis JshopStore5的sqlmap的xml錯(cuò)誤,NestedSQLException錯(cuò)誤[未登錄]
          2007-01-18 19:44 | BeanSoft
          強(qiáng)烈建議 dudu 加入全文索引... 沒搜索這么多 blog 也是很浪費(fèi)啊...  回復(fù)  更多評(píng)論
            
          # re: ibatis JshopStore5的sqlmap的xml錯(cuò)誤,NestedSQLException錯(cuò)誤
          2008-10-20 20:40 | Guest
          我也是這樣改的,不過仍然還是錯(cuò)誤。。。搞不明白呢。  回復(fù)  更多評(píng)論
            
          # re: ibatis JshopStore5的sqlmap的xml錯(cuò)誤,NestedSQLException錯(cuò)誤
          2010-02-06 13:09 | ossoftwaare
          好內(nèi)容,以前研究過,不過好久了, 最近寫了幾句,也發(fā)現(xiàn)了這個(gè)問題  回復(fù)  更多評(píng)論
            
          # re: ibatis JshopStore5的sqlmap的xml錯(cuò)誤,NestedSQLException錯(cuò)誤
          2010-12-10 14:48 | LingShame
          @junmy
          你走得路,先人已經(jīng)走過N多次了.
          你再走來,不覺得可恥嗎?  回復(fù)  更多評(píng)論
            

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2010年12月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          常用鏈接

          留言簿(5)

          隨筆檔案

          UML

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 会理县| 嫩江县| 富顺县| 安仁县| 玛纳斯县| 新乡县| 公主岭市| 惠安县| 扎鲁特旗| 临湘市| 长宁区| 威海市| 津南区| 探索| 仁寿县| 张家界市| 平潭县| 景东| 靖西县| 涿鹿县| 水富县| 德惠市| 道孚县| 隆德县| 赤峰市| 合阳县| 新昌县| 文山县| 襄垣县| 泗洪县| 佛山市| 洪雅县| 水富县| 庆城县| 江津市| 望谟县| 新乡市| 海阳市| 富阳市| 庆城县| 娄底市|