今天工作中使用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中在寫上傳回值,那就是畫蛇添足,同時還會報出上面那個非常讓你迷惑的錯誤資訊。