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 581527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:35:18+00:00 2026-05-13T14:35:18+00:00

Does anyone know how what Spring Jdbc template method I could use to execute

  • 0

Does anyone know how what Spring Jdbc template method I could use to execute this ‘upsert’ or an alternative approach that would also perform the operations in one database call?

UPDATE jasper_report SET Uri = 'update' WHERE ReportId = 99;
IF @@ROWCOUNT = 0 AND Exists(Select 1 FROM report Where Id = 99)
BEGIN   
    INSERT INTO jasper_report  (ReportId, Uri) VALUES (99, 'insert') 
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-05-13T14:35:18+00:00Added an answer on May 13, 2026 at 2:35 pm

    Turns out I was close but forget a step.

    I had to change the query itself to:

    BEGIN 
      UPDATE jasper_report SET Uri = ? WHERE ReportId = ? 
      IF @@ROWCOUNT = 0 AND EXISTS(SELECT 1 FROM report WHERE Id = ?) 
      BEGIN 
           INSERT INTO jasper_report  (ReportId, Uri) VALUES (?, ?) 
      END 
    END
    

    Then in my Dao only needed to use Spring’s JdbcTemplate update method. It looks something like this:

    @Repository("jasperReportsDao")
    public class JasperReportsDaoImpl extends JdbcTemplate implements JasperReportsDao {
    
        @Override
        public void saveJasperReport(JasperReport report) {
            // If a record already exists, do an update, otherwise, do an insert
            int rowsAffected = this.update(UPSERT_JASPER_REPORT, new Object[] { report.getUri(), report.getId(),
                                   report.getId(), report.getId(), report.getUri()} );
    
            if(log.isDebugEnabled()) { log.debug("Rows affected: " + rowsAffected); }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to customize the form fields that Spring Roo generates so
Does anyone know where some Spring style integration images can be found for use
Does anyone know how to step into the target method of a class that
Does anyone know how to use a custom ThemeSource in spring? I have seen
Does anyone know if Spring has any extensions that allow for configuring its ApplicationContext
does anyone know how to fix this issue? it happens on a spring 3
Does anyone know how to construct a format string in .NET so that the
Does anyone know if it is possible to create a single connection string that
Does anyone know if there is a framework out there that is able to
I am using Spring Jdbc template and for that I have context.xml <property name=driverClassName

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.