2

Java Mybatis Oracle

I have following mybatis statement in xml file

<update id="updateOfferIndex" parameterType="java.util.List">
   <foreach collection="list" item="offer"  index="index"  separator=";" >
        UPDATE  offer set indx=#{offer.idx} WHERE id=#{offer.eId}
    </foreach>

I am getting following error, can any one help ?

### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

### The error may involve com.dao.linear.upsell.LinearUpsellDao.updateOfferIndex-Inline
### The error occurred while setting parameters
### SQL: UPDATE  offer set indx=? WHERE id=?   ;       UPDATE  offer set indx=? WHERE id=?
### Cause: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
3
  • how does this call looks like in java? I thought it is not possible to call multiple statements with one execute. Commented Oct 27, 2015 at 15:50
  • upsellDao.updateOfferIndex(offers); Commented Oct 27, 2015 at 15:55
  • possible duplicate stackoverflow.com/questions/17928799/… Commented Oct 30, 2015 at 13:28

2 Answers 2

4

I resolve by insert BEGIN-END statements in this way:

BEGIN
<foreach collection="list" item="offer"  index="index"  separator=";" >
        UPDATE  offer set indx=#{offer.idx} WHERE id=#{offer.eId}
</foreach>;
END;

I hope this resolves.

Sign up to request clarification or add additional context in comments.

Comments

2

Looks like the last semicolon has not been appended:

    ### SQL: UPDATE  offer set indx=? WHERE id=?;       
    UPDATE  offer set indx=? WHERE id=?;

And this is coherent with the mybatis documentation about the foreach's separator:

The element is smart in that it won’t accidentally append extra separators.

Try adding a semicolon to the XML mapping:

  <foreach collection="list" item="offer"  index="index"  separator=";" >
        UPDATE  offer set indx=#{offer.idx} WHERE id=#{offer.eId}
  </foreach>
  ;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.