Help me to return the primary key after insert the row

Hi
I am using JDBC, with oracle database. i have welformed normalization tables .i am inserting parent table with dynamic sequence number as primary key .after inserting i need inserted row primary key .how to get the inserted row primary key with out using select statement
please help me
Thanks in advance
Edited by: 849614 on Apr 4, 2011 5:41 AM
Edited by: 849614 on Apr 4, 2011 5:54 AM

Hello
If I undestand you, I think you should do this:
Connection conexion = dataSource.getConnection();
int idCenter=-1;
String query = "Begin Insert into CENTER (NAME_CENTER) values (?) returning ID_CENTER into ?; end";
callableStatement = conexion.prepareCall(query.toString());     
     callableStatement.setString(1, "Center name");               
     callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
          callableStatement.executeUpdate();
          idCenter=callableStatement.getInt(2);
This way, you have in idCenter the primary key of the line that has just been inserted.
Edited by: cris on 05-abr-2011 5:28

Similar Messages

  • Returning autogenerated primary key after insertion

    Hi
    I am inserting a row into the database using simple jdbc statement. The primary key for that row is autogenerated by the database.
    Is there any way to get the primary key and return it to the user?

    PreparedStatement ps = con.preparedStatement("INSERT INTO Table (title, name) VALUES ("test", "name")", PreparedStatement.RETURN_GENERATED_KEYS);
    ps.executrUpdate();
    ResultSet rs = ps.getGeneratedKeys();
    while (rs.next()) {
    primaryKey = rs.getInt(1);
    }

  • Knowing the primary key columns of the given table

    Hi,
    How can I get the primary key columns of the given table?
    Regards,
    Sachin R.K.

    You can find the constraint_name from all_constraints/user_constraints for constraint_type = 'P' (which is the primary key constraint).
    And then see which columns are in for the constriant_name
    in all_cons_columns/user_cons_columns view.
    Below is the example
    select acc.column_name from
    all_cons_columns acc, all_constraints ac
    where acc.constraint_name = ac.constraint_name
    and acc.table_name = 'DEPT' AND acc.owner = 'SCOTT'
    and ac.constraint_type = 'P'
    Hope this helps
    Srinivasa Medam

  • My early Intel iMac running Snow Leopard will not boot past the apple logo. I have tried holding the c key and inserting the install disk, but nothing. What do I try next?

    My early Intel iMac running Snow Leopard will not boot past the apple logo. I have tried holding the c key and inserting the install disk, but nothing. What do I try next?

    I have tried resetting PRAM and all other items listed in the Apple support site. This happened after an update to iTunes was added. Also this is happening to other people. Please help.

  • Batch processing problem: Seeing the primary key (id) in the test cases...

    Another problem we seem to be having is how to read the primary key into a base attribute of an entity.
    In batch processing, we may define the "id" as the primary key on the table. We need to get that id and the foreign key ids into the base attributes in the rule set...
    How do we go about doing that?

    Perhaps better, if you could give me a sample xml config with global and one entity. The only attribute in the entity should be the id... The id should be the primary key in both OPA and Oracle...
    The global table in oracle would contain a single column with the global id.
    The child table in oracle would contain 2 columns -> one for the global ref id and one for the child key...
    I think you will find problems.
    As a note we have duct-tape solved this by creating views and making column copies in the views of the child id and then mapping the id in oracle to the duplicate column in the view.
    So our child view contains the child table with the child id repeated twice so that we can map...

  • How to provide the license key after having the evaluation copy expired for SQL Server 2012 Standard?

    How to provide the license key after having evaluation copy expired for SQL Server 2012 Standard?
     I couldn’t figure out how to provide the license key after having
    evaluation copy expired for SQL Server 2012 Standard
     Thank you
     Best
     Jamal

    The following blog is on the topic: Upgrading from SQL Server 2012 Evaluation Edition
    Kalman Toth Database & OLAP Architect
    Free T-SQL Scripts
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • For the Primary Key Field with the combination of other fields

    Hai
    I Have a problem in creating trigger for the following
    the problem goes like this..
    i have a table with the fields
    fld1 (varchar2(6) fld2(varchar2(20)) fld3 (number)
    the fld1 is a primary key.
    here in this table i am inserting the values ..
    At the time of inserting the fld1 should get the part value of fld2
    say if new value for fld2 is "SAM & CO" then
    it should take the first letter and then followed by the sequence..
    i.e., the fld1 is the combination of a
    letter + firt letter of the fld2 + sequence
    fld1 fld2 fld3
    CS001 SSSSS 324234
    CP001 PPPPP 5345435
    CS002 SSSS 53543543
    Here the Sequence should vary depending on the alphabet of the fld1
    if P the the Sequence should be the next number of fld1 to P
    i.e.,
    if i add the value like this
    insert into tname(fld2,fld3) values('PQQQQ',34343)
    then it should be inserted as
    CP002 PQQQQ 34343
    I need the solution for this..
    Thanx
    Gaya3
    thanx
    gaya3

    There are not enough details to be sure since you have not provided the mappings. From just the error, it looks like you are using the tableC.tableA_ID field as the foreign key in the ManyToOne relationship to A, but have marked it as insertable=false, writeable=false, meaning that it cannot be updated or used for inserts.
    Either make it writable (set the settings to true), or add another basic mapping/attribute in the entity for TableC that maps to the field which you can use to set when you insert a new tableC entity. A simple example is available at
    http://wiki.eclipse.org/EclipseLink/Examples/JPA/2.0/DerivedIdentifiers
    Best Regards,
    Chris

  • How to find out the primary key of oracle apps tables

    Hii,,
    My Question is How to find the primary key in the apps table...Is there any Query or other way to find out???
    for eg.
    I want to find out the primary key of the AP_INVOICES_ALL table...just tell me how can i get the primary key of this table.
    I am currently using toad for the query..
    Please guide me...

    you can define the primary key when you create table
    or add the primary key after the table creation by 'ALTER TABLE ... ADD constraint pk_nme primary key (col1, col2)';
    you could use below sql to check the detail of primary key:
    1) check out the table definition directly:
    select dbms_metadata.get_ddl('TABLE','EMP') FROM DUAL;
    2) check out the columns of primary key:
    select * from user_constraints where constraint_type='P' AND table_NAME='EMP';
    select * from user_cons_columns where CONSTRAINT_NAME='PK_EMP';And BTW, it is madam, not sir. :)
    Edited by: PhoenixBai on Dec 17, 2010 1:07 PM

  • How to find out the primary key column of a database table?

    Hi
    Given the following scenario :
    Given an inputfield, the user can enter a table name. The code behind will base on the table name given and extract out the fieldname of the primary key and concatenate the two field to become a unique string.
    Eg. Order ID and Product ID make out a primary key.
    How do i achieve that? Any code sample?
    Regards,
    Rayden

    Check the below code :
    REPORT zTest no standard page heading.
    data : i_DD03P like DD03P occurs 0 with header line.
    data v_table like DCOBJDEF-NAME.
    parameters : p_table like dd02l-tabname.
    start-of-selection.
    v_table = p_table.
    CALL FUNCTION 'BDL_DDIF_TABL_GET'
      EXPORTING
        NAME                = v_table
       STATE               = 'A'
       LANGU               = 'E'
    IMPORTING
      GOTSTATE            =
      DD02V_WA            =
      DD09L_WA            =
    TABLES
       DD03P_TAB           = i_DD03P
      DD05M_TAB           =
      DD08V_TAB           =
      DD12V_TAB           =
      DD17V_TAB           =
    EXCEPTIONS
       ILLEGAL_INPUT       = 1
       OTHERS              = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    loop at i_DD03P.
    if i_dd03p-KEYFLAG = 'X'.
    write:/ 'Key fields', i_dd03p-FIELDNAME.
    endif.
    endloop.
    Thanks
    Seshu

  • Primary key column as the key of the cache

    Hi All,
    I am implementing a cache backed by HibernateCacheStore for a table. Cache contains key as the primary key of the table and value as the entire row in object format. the primary key is generated by hibernate.
    when i am inserting new rows through coherence (i.e cahce.put) what persistence strategy should is use to set the cache entries.
    I cannot use cache.put (key, value) because key is the primary key of the table which is not generated yet.
    and if i use the session.save(value) the persisted value is not in the cache.
    is there any mechanism to map the cache key as the primary key column of the table.
    Regards
    S

    Hi -
    Using Hibernate as a CacheStore for Coherence, the key of the cache entry is also the key of the entity
    being stored via Hibernate. For this reason keys for new cache entries must be generated ahead of time.
    A UUID can be used. The commons component of the Incubator project has a key generation utility that
    might be worth looking at.
    /Mark

  • Key value does not currently exist in the primary key table error

    Im testing out a form and creating a new insert once all the fields are filled in it wont allow me to move on and comes up with this error message;
    key value does not currently exist in the primary key table
    Is this becuase the form contains foriegn keys which reference different tables which fields are not dispalyed on this form?
    If so how to I link the other forms together so that when i create a new record in this form it will automaticaly create the primary key entry in the other form to allow the insert of the referenced foreign key in this form?
    does this make sense?

    It seems that it has the table in which you'r inserting is a foreign key table.
    Take the emp& dept table example in the schema scott/tiger.
    Say we have deptno 10, 20, 30, 40 in the dept table.
    We make a form for emp table and insert into this form.
    Now, we'r bound to insert deptno 10, 20, 30, 40 into this emp form. This form will not allow us to insert deptno 50 as it doesn't exist in the primary key column in dept table.
    Obviously if a department doesn't exist in the company, it doesn't make sense to assign the employees to that department.
    So for this purpose, we need to add a department in the dept table then we can insert values in the emp table for that department.
    For this purpose, I suggest to make a button on the mp form and invoke the dept form and add a new department to it and then insert into emp table.
    The same scenario can be applied in your case.

  • How to khow how many foreign key are referenceing the primary key

    sir i would like to know that how many foreign key are referencing the primary key of a table
    is any command to know the table name
    please suggest
    thanks in advance..

    In the query below, table_name is the name of the table whose primary key is referenced.
    SELECT b.owner owner
    ,b.constraint_name foreign_key
    ,b.constraint_type constraint_type
    ,b.table_name referencing_table
    ,b.r_constraint_name primary_key
    ,c.table_name referenced_table
    ,c.column_name referenced_column
    FROM all_constraints a
    ,all_constraints b
    ,all_cons_columns c
    WHERE a.owner = b.owner
    AND a.table_name = :table_name
    AND a.constraint_type = 'P'
    AND b.r_constraint_name = a.constraint_name
    AND b.constraint_type = 'R'
    AND c.constraint_name = a.constraint_name
    AND c.owner = a.owner;
    If the name of the primary key is known, the query below
    select * from all_constraints where constraint_type = 'R' and r_constraint_name = :pk_name

  • Insert record and return the primary key

    Okay, I need to insert a record into a MSSQL database and return the primary key of that record. Im using the following code which is obviously wrong as I'm getting either 'NULL' or 'com.microsoft.jdbc.base.BaseResultSet@1d520c4' returned depending on the ways I've tried. The primary key is an int value called clientID which is incremented by one each time a new record is added.
    // set the prepared statement
                String sql="INSERT INTO Client(username, country, clientIP, browser, os) VALUES(?,?,?,?,?)";
                PreparedStatement pstmt = conn.prepareStatement(sql);
                pstmt.setString(1, inUserName);
                pstmt.setString(2, inCountry);
                pstmt.setString(3, inClientIP);
                pstmt.setString(4, inBrowser);
                pstmt.setString(5, inOS);
                // Insert the row
                pstmt.executeUpdate();
                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery("SELECT SCOPE_IDENTITY()");
                System.out.println("Result "+rs);The primary key value is needed so that it can be used as a foregin key in another table. Am I going about this the correct way? Any help, pointers or code fixing would be appreciated.....

    Yes. I tried this way but I only ever get the answer
    of 0 when i print our the result! Not really sure
    whats happening.That's because you don't print a ResultSet like that. In order to get the key out, you have to do this:
    int key = 0;
    while (rs.next())
        key = rs.getInt(1);What were you thinking with your code?
    You might want to do this in a transaction. If the INSERT fails, you'll want to roll back.
    The "select @@identity" is correct for M$ Access, SQL Server, and Sybase. I believe it's also correct for MySQL, but I'm not 100% certain of that.
    %

  • How to get the new Primary Key after the Automatic Row Processing (DML)

    Hi,
    I have a nice master detail form.
    I want, immediately after submitting the page when creating a new record in the master table, that the user may input the associated table (the detail table). For that I have created a branch that goes back to the very same page after creating the record (ie submitting the page with the button Create). In the Action of the branch, i have put P30_FICHE_ID (the item containing the primary key of the master table) with its value : &P30_FICHE_ID.
    Unfortunately I see that the item is not populated with the very new primary key. it seems normal becaus after submitting the page the tiem is not populated. This is my question : how to retrieve the newly created primary into the item P30_FICHE_ID in order to begin immediately to add rows to the detail table ?
    Hope I'm clear. My english not perfect.
    Thank you for your kind help !
    Christian
    Edited by: Christian from France on Oct 16, 2009 6:36 AM

    Christian,
    After creating Master-detail form, goto your Detail page. In this page you can see one conditonal brach which will point to 'Master' page.
    Edit this branch and here you can see this branch fires when request is in 'SAVE,DELETE,CREATE' (in Expression1). Now change the value in Expression1 to 'SAVE,DELETE'. This will do the needful :-)
    Cheers
    Hari
    Edited by: Hari_639 on Oct 16, 2009 8:02 PM

  • Getting Too many objects match the primary key oracle.jbo.Key...

    Hi,
    I am working on jDEV Version 11.1.1.2.0. In one of my page I am getting exception like "*Too many objects match the primary key oracle.jbo.Key......*".
    I have a Items EO and it's Child EO. I am using view criteria in Items VO and drag and dropped this as a Query panel (search criteria). On the right side top I am displaying results in a table. Below I have a Master form and Child table where users can add / edit the Model and it's child values. When user clicks on Save button I am calling BPELprocess (WSDL) which inserts into 3 other systems and return me the message. After Clicking the Save button and displaying the message if I search for the same model (which I created) then it will throw error like above. If I search for different Model it won't throw the error.
    For example I have created "TestModel" and If I type letter "T"in Input box and search then it will throw error. If I search for some other models which are not starting with letter "T" then it works fine.
    Any idea what may be the reason? Instead of calling services in the Save button I drag and dropped "Commit" button and tested then it works fine.
    This is really critical for my project. It would be great if someone can help me on this.
    Thanks
    MC

    JBO-27102: DeadViewRowAccessException
    Reason: Trying to access a ViewRow which is part of an obsolete/invalid collection. This could happen if a reference to the ViewRow is held by some business logic while the containing view object was removed.
    Solution: Find the referenced ViewRow either by re-querying or using findByKey methods to get a valid reference to the ViewRow. instead of create() can you try createInsert() or createAndInitRow()

Maybe you are looking for

  • Animated gif not working

    Hi All, Animated gif seems to have an issue in flex. seemingly a swf will solve the problems. Does anyone have a swf corresponding to the progress indicator? Any help will be highly appreciated. Thanks Yukti

  • How can I get Data from the Sound cart in Labview? Does a VI exist?

    How can I get Data from the Sound cart in Labview? Does a VI exist?

  • How to resolve ORA-00001 Error in SQL Insert?

    Hi all, I need your appreciated help. I make a plsql procedure that is inserting a row according cursor value, I'm having oracle error ORA-00001: unique constraint (constraint_name) violated. You may see this message if a duplicate entry exists at a

  • Barcode reader with SAP

    Hi Gurus, i want to use barcode truck  but i dont any idea how to use in SAP Can anyone make a suggestion ?

  • LR cannot Import - Unknown Error

    I am getting this error message when trying to import a catalog "Lightroom could not import because of Unknown Error". The catalog I am attempting to import contains about 6000 images and was built by the beta during the Beta phase.  It opens fine by