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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:52:16+00:00 2026-05-30T04:52:16+00:00

Below is the code I am using to save a record in the database

  • 0

Below is the code I am using to save a record in the database and then get the generated primary key.

public void save(User user) {
    // TODO Auto-generated method stub
    Object[] args = { user.getFirstname(), user.getLastname(),
            user.getEmail() };
    int[] types = { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR };

    SqlUpdate su = new SqlUpdate();

    su.setJdbcTemplate(getJdbcTemplate());
    su.setSql(QUERY_SAVE);

    setSqlTypes(su, types);

    su.setReturnGeneratedKeys(true);
    su.compile();

    KeyHolder keyHolder = new GeneratedKeyHolder();

    su.update(args, keyHolder);

    int id = keyHolder.getKey().intValue();

    if (su.isReturnGeneratedKeys()) {
        user.setId(id);
    } else {
        throw new RuntimeException("No key generated for insert statement");
    }
}

But its not working, It gives me following error.

The generated key is not of a supported numeric type. Unable to cast [oracle.sql.ROWID] to [java.lang.Number]

The row is being inserted in the database properly. As well I could get the generataed primary key when using MS SQL database but the same code is not working with the ORACLE 11G.

Please help.

  • 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-30T04:52:17+00:00Added an answer on May 30, 2026 at 4:52 am

    As in the comment, oracle rowid’s are alpha numerical so can’t be cast to an int.

    Besides that, you should not use the generated rowid anywhere in your code. This is not the primary key that you defined on the table.

    MS SQL has the option to declare a column as a primary key which auto-increments. This is a functionality that does not work in oracle.

    What I always do (regardless if the db supports auto-increment) is the following:

    select sequenceName.nextval from dual
    

    The value returned by the previous statement is used as the primary key for the insert statement.

    insert into something (pk, ...) values (:pk,:.....)
    

    That way we always have the pk after the insert.

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

Sidebar

Related Questions

I am using the code below to save and restore the window position and
This code below is using the FWRITE function. however i wish to save the
i am using the code below to save an image in the NSDocumentDirectory -(BOOL)saveImage:(UIImage
I have just begun Rails 3. I have generated the below code using the
My ASP.NET application return PDF file to user using code below Context.Response.Clear(); Context.Response.ContentType =
i am using below code to change the the font type of text view.
I am using below code to create a reminder in Google calendar (using Google
Currently i'm using below code which works well. $(#topperAtBaseLevel:visible, #lowerAtBaseLevel:visible, #midAtBaseLevel).hide(); any optimised code?
I have the code below: using (SqlCommand command = new SqlCommand()) { command.CommandType =
I would like to implement a parallel version of the code below using threads

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.