ibatis crud返回值问题


insert into BOOKS (bookNum, bookName, author, publisher,price,
state, quality) values ( #bookNum:VARCHAR#, #bookName:VARCHAR#,
#author:VARCHAR#,#publisher:VARCHAR#, #price:FLOAT#,
#state:INTEGER#, #quality:INTEGER#)


SELECT @@IDENTITY AS bookId

 

在执行insert是才会返回插入的id

    public int update(Book book) throws DatabaseException{
        String method = "update";
        int result = 0;
        try {
            result = update("updateBook", book);
            debug("", method, Constant.LOG_UPDATE_SUCCESS);
        } catch (RuntimeException e) {
            error("", method, Constant.LOG_UPDATE_FAIL);
            throw new DatabaseException(DatabaseException.DB_Message, e);
        }
        return result;
    }

///////////////////////////////////////////////

对于删除


        DELETE FROM BOOKS WHERE BookId = #bookId#
 

直接返回影响记录集

    /**
     *
     * @param bookId
     * @throws DatabaseException
     * @return int >0:delete success  <0: delete fail
     */
    public int deleteBook(int bookId) throws DatabaseException{
        String method = "deleteBook";
        int result = -1;
        try {
            result = (Integer)this.delete("deleteBook", bookId);
            debug("", method, Constant.LOG_DELETE_SUCCESS);
        } catch (RuntimeException e) {
            result = -1;
            error("", method, Constant.LOG_DELETE_FAIL);
            throw new DatabaseException(DatabaseException.DB_Message, e);
        }
        return result;
    }

 

你可能感兴趣的:(ibatis)