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

  • Home
  • SEARCH
  • 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 6327887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:21:36+00:00 2026-05-24T17:21:36+00:00

Im new to sql and im facing a problem with the below native query

  • 0

Im new to sql and im facing a problem with the below native query

 public void saveOfflineBatchDetails(BigInteger user_id) {

    em.createNativeQuery("INSERT INTO rst_offline_transaction_batch (created_date , user_id)" +
            "VALUES('?1', ?2)")
            .setParameter(1, new java.util.Date())
            .setParameter(2, user_id)
            .executeUpdate();
}

It doesn’t pass the values to the database. the created date should be the today’s date and time. Can anyone tell me whats wrong in this query.
Thanks a lot

  • 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-24T17:21:37+00:00Added an answer on May 24, 2026 at 5:21 pm

    You generally don’t include the single quotes for parameterised queries. Try:

    VALUES(?1, ?2)
    

    (without the quotes around the ?1). Otherwise it’s hard (for both readers and parsers) to tell whether you wanted parameter 1 or the literal value ?1 to be inserted.

    You should also check the return value from executeUpdate() to see if it thinks it affected any rows. This will probably give you zero but it’s worth checking anyway.

    And, finally, I think dates require special handling as per:

    setParameter(1, new java.util.Date(), TemporalType.DATE);
    

    This is because the Java Date object is not a date at all but a timestamp – you need to ensure you select the correct temporal object type so that the right value is placed in the query.

    So, in short, something like:

    int affected = em.createNativeQuery(
        "INSERT INTO rst_offline_transaction_batch (" +
        "    created_date," +     // ?1
        "    user_id" +           // ?2
        ") VALUES (?1,?2)"
        )
        .setParameter(1, new java.util.Date(), TemporalType.DATE)
        .setParameter(2, user_id)
        .executeUpdate();
    // Check affected.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a problem for writing an sql query which should be easy
My problem is: each entry in view calls new sql query altough i used
I am writing some new SQL queries and want to check the query plans
I'm loading a SQL Server 2000 database into my new SQL Server 2005 instance
I am totally new to SQL . I have a simple select query similar
I am new to Perl coding. I am facing a problem while executing a
I am facing a really weird error,while trying to insert into a table called
I facing a problem regarding the import of an excel file into mysql through
I am facing an unusual problem in Oracle SQL Developer. When I try to
Question: The new SQL Server 2008 database returns me values formatted English (date/float). Is

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.