iBaits中,關於insert傳回值的問題(注意!!!不必寫resultClass= "java.lang.Integer",方法的傳回值就是int)

來源:互聯網
上載者:User

今天工作中使用iBaits寫SQL,其中一個是insert語句



在sqlMap中我這麼寫了,<insert

                                      parameterClass="...."

                                      resultClass="java.lang.Integer" >


於是報出了以下的錯誤:

org.xml.sax.SAXParseException: Attribute "resultClass" must be declared for element type "insert".


首先 先不說我的錯誤,主要是這個錯誤資訊,在網上查了一下,有問題。


正確的 錯誤資訊應該是:

org.xml.sax.SAXParseException: Attribute "resultClass" must not be declared for element type "insert".

 

然後 分析一下錯誤的原因:

 

在JDBC中我們都知道的Statement的兩個方法

 ResultSet executeQuery (String  sql)
          Executes the given SQL statement, which returns a single ResultSet object.
 int executeUpdate (String  sql)
          Executes the given SQL statement, which may be an INSERT , UPDATE , or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

 

      這兩個方法,其中結果集就是我們一般定義的SQLID001Output.java,但是作為更新或插入的件數,是系統自動返回的,所以我們不需要設定,在用iBaits中executeForUpdate方法的傳回值就是int ,如果我們在sqlMap中在寫上傳回值,那就是畫蛇添足,同時還會報出上面那個非常讓你迷惑的錯誤資訊。

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.