Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:41:06+00:00 2026-06-09T18:41:06+00:00

I can not find an example of mapping in MyBatis that I can replace

  • 0

I can not find an example of mapping in MyBatis that I can replace the below code with.

“if sqlcode <> 0” If no update takes place then do an insert

Any sugestions? 🙂

as
begin
  execute SetDefaultIsolationLevel
  update COMPANYLEVEL 
  set 
    companylevelid = @companylevelid, 
    companynameid = @companynameid, 
    level = @level, 
    memo = @memo,
    operator = @operator,
    changed = getdate(*)
  where
    companynameid = @companynameid
  if sqlcode <> 0
  BEGIN
    insert into COMPANYLEVEL 
        (companylevelid,companynameid,level,memo,operator,changed)
    values
        (@companylevelid,@companynameid,@level,@memo,@operator,getdate(*)) 
  END
  commit transaction
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:41:08+00:00Added an answer on June 9, 2026 at 6:41 pm

    I don’t think MyBatis has any mapping to say “try an update, if that fails do an insert”. If you want that done in one round trip to the database, then a stored procedure is appropriate. You can call this stored procedure from MyBatis, but the if/else logic would be in the stored proc.

    If you are trying to get rid of the stored proc, then you’ll need a two step check in your code. An update in MyBatis returns the number of rows updated (via the JDBC driver), so if that is zero, then you can call a MyBatis insert mapping. In cases where an insert occurs, it would require two round trips to the database.

    You could also do an “upsert” using a MERGE statement in a stored proc, but that of course isn’t related to MyBatis other than MyBatis can call your stored proc. It looks like you are using Sybase? If so, I’m not sure if Sybase has upserts – link to research: Upsert (update or insert) in Sybase ASE?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where can I find a RSA encrypt example that does not use NoPadding? --update
all. Maybe i've not googled enough, but i can't find any example on this
I can't find the is not operator in C#. For example I have the
I faced a problem that I can not find a way to change the
I cannot find a simple example about my question above: how can i detect
I can not find how to implement a design in C++. In the language
I can not find a mod_go for deploying Go web applications. Is there any
When mapping an Exception to 404 page, the Spring Security tags can't find the
More and more, I'm seeing searches that not only find a substring in a
Cannot find any example on Google.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.