Auto Increment ID Field Table in the Oracle Database (insert new record)

I have been using the MySQL. And the ID field of the database table is AUTO INCREMENT. When I insert a new record into a database table, I can have a statement like:
   public void createThread( String receiver, String sender, String title,
                             String lastPostMemberName, String threadTopic,
                             String threadBody, Timestamp threadCreationDate,
                             Timestamp threadLastPostDate, int threadType,
                             int threadOption, int threadStatus, int threadViewCount,
                             int threadReplyCount, int threadDuration )
                             throws MessageDAOSysExceptionand I do not have to put the ID variable in the above method. The table will give the new record an ID number that is equivalent to the ID number of the last record plus one automatically.
Now, I am inserting a new record into an Oracle database table. I am told that I cannot do what I am used to doing with the MySQL database.
How do I revise the createThread method while I have no idea about what the next sequence number shall be?

I am still very confused; in particular, the Java part. Let me try again.
// This part is for the database table creation
-- Component primary key sequence
CREATE SEQUENCE dhsinfo_page_content_seq
    START WITH 0;
-- Trigger for updating the Component primary key
CREATE OR REPLACE TRIGGER DHSInfoPageContent_INSERT_TRIGGER
    BEFORE INSERT ON DHSInfoPageContent //DHSInfoPageContent is the table name
    FOR EACH ROW WHEN (new.ID IS NULL) // ID is the column name for auto increment
    BEGIN
        SELECT dhsinfo_page_content_seq.Nextval
        INTO :ID
        FROM DUAL;
    END;/I am uncertain what to do with my Java code. (I have been working with the MySQL. Changing to the Oracle makes me very confused.
   public void updateContent( int groupID, String pageName, int componentID,
                              String content, Timestamp contentCreationDate )
                               throws contentDAOSysException
   // The above Java statement does not have a value to insert into the ID column
   // in the DHSInfoPageContent table
      Connection conn = null;
      PreparedStatement stmt = null;
      // what to do with the INSERT INTO below.  Note the paramether ID.
      String insertSQL = "INSERT INTO DHSInfoPageContent( ID, GroupID, Name, ComponentID, Content, CreationDate ) VALUES (?, ?, ?, ?, ?, ?)";
      try
         conn = DBConnection.getDBConnection();
         stmt = conn.prepareStatement( insertSQL );
         stmt.setInt( 1, id ); // Is this Java statement redundant?
         stmt.setInt( 2, groupID );
         stmt.setString( 3, pageName );
         stmt.setInt( 4, componentID );
         stmt.setString( 5, content );
         stmt.setTimestamp( 6, contentCreationDate );
         stmt.executeUpdate();
       catch
       finally

Similar Messages

  • How can we clone the Oracle database in new Oracle Home

    Hi,
    I would like to clone oracle database into new oracle home. How can we set it using OEM.
    I am using 10g grid control. Target db is on solaris
    Thanks
    Naveen

    after logging into target database, under maintenance tab, data movement header; ther is "clone database" option. When you click on it; you'll see :
    Clone Database uses RMAN to duplicate a database from:
    -- An open database in ARCHIVELOG mode, or
    -- An open database in NOARCHIVELOG mode (restart required), or
    -- A saved working directory from previous cloning
    Clone Database performs the following operations:
    -- Backup each database file and store it in a working directory
    -- Transfer each backup file from source to destination host
    -- Restore each backup file to existing destination Oracle Home
    -- Recover the cloned database with saved archived log files
    -- Open the cloned database with resetlogs
    It seems to be for cloning to a different host, but i guess you can chose the same host for source and destination. (I've never used cloning on em by the way :))
    But firstly, you should create a new oracle home, you can simply copy your oracle home with a new name (cp -R /oracle/app/oracle/product/10.2.0 /oracle/app/oracle/product/10.2.0.new) or make a new installation.
    I suggest you to do this cloning with CLI. You should take a full backup with RMAN, copy the oracle home, create a new initNEWSID.ora file and nomount the database, restore (or simply copy) controlfiles, restore database (with set newname commands), recover database, open resetlogs.

  • Receiver JDBC: Error while doing the Deleting and Inserting new records

    Hi All,
              I am doing Idoc to JDBC scenario. In this I am collecting & bundling different type of Idocs and then sending to the JDBC receiver. My requirement is to delete the existing records in the database and insert the new records. I have configures as mentioned in the link
    Re: Combining DELETE and INSERT statements in JDBC receiver
    In the above link its shows for single mapping. In my scenario I am using multi mapping for collecting idocs in BPM. If I configured for normal mapping then it is working fine(Deleting existing records and Inserting new record). Whenever I am using multi mapping then I am getting following error in the receiver JDBC communication channel u201CError while parsing or executing XML-SQL document: Error processing request in sax parser: No 'action' attribute found in XML document (attribute "action" missing or wrong XML structure)u201D . Can you please tell me what might be the problem.
    Thanks & Regards,
    T.Purushotham

    Hi !
    check this out:
    JDBC - No 'action' attribute found in XML document - error
    JDBC receiver adapter: No 'action' attribute found in XML document
    It appears that the inbound payload (the one that is going from XI to the JDBC adapter) does not have the requiered tag to specify which SQL action to execute in the receiver system. Maybe the multimapping is not creating the desired output message format.
    Regards,
    Matias.

  • Putting Partition in tables in the Oracle database

    How do I create partitions in the various SAP datases running on Oracle?

    Hi,
    I'm sorry to say you've reached the wrong forum, as this one's for MaxDB and liveCache only. I'll try to find a more suited one.
    Can you maybe tell us which:
    - SAP Application plattform (Netweaver, BI ...) you are using?
    - operating system (OS) your Oracle DB is running on?
    Regards,
    Roland

  • Auto-increment  identity column through procedure in oracle 10g on windows

    Hi,
    I need identity primary key which should be auto increment before while inserting data into table.
    for this i had use sequence and then trigger to increment it.
    but now i need to increment it in Procedure, while my procedure is having code to insert data in same table which has primary key

    Hi,
    SNEHA RK wrote:
    Hi,
    I need identity primary key which should be auto increment before while inserting data into table.
    for this i had use sequence and then trigger to increment it.Right. Some database products have auto-increment columns, and they are really handy. Unfortunately, Oracle does not have auto-increment columns. A sequence is an auto-increment object, and it's the right way to automatically generate unique identifiers, but you need to explicity reference the sequence, either in you DML statements, or in a trigger that will automatically fire before a DML statement.
    but now i need to increment it in Procedure, while my procedure is having code to insert data in same table which has primary keyAre you saying that you need to increment the sequence, completely aside from INSERTing into the table?
    If so, just reference sequence_name.NEXTVAL wherever you want to. In PL/SQL, you can say
    SELECT  sequence_name.NEXTVAL
    INTO    number_variable
    FROM    dual;This works in any version of Oracle, but starting in Oracle 11, you also have the option of referencing te sequence without using dual, or any other table.
    I hope this answers your question.
    If not, post a complete script that people can run to re-create the problem and test their ideas.
    For example:
    -- Here are the table and the seqauence that I created:
    CREATE TABLE table_x ...
    CREATE SEQUENCE ...
    -- Here is the BEFORE INSERT trigger I wrote:
    CREATE OR REPLACE TRIGGER ...
    -- The trigger works exactly how I want it to in statements like this:
    INSERT INTO table_x ...
    -- So there are no problems (that I know of) with anything up to this point.
    -- Now I want to use the same sequence to ...
    -- so that when I execute a statement like this
    -- then the next time  I add a new row to the orginal table, like this
    INSERT INTO table_x ...
    -- then the contents of table_x should be ... because ...

  • UCCX What field and table of the UCCX database contains the max time to answer a call?

    What field and table of the UCCX database contains the max time to answer a call?
    Also when performing an aggregate function on CSQ queries do I group on target id?  Is that the unique identifier?

    Hi Christina,
    Please find the information of the UCCX DB schema in the following table:
    http://www.cisco.com/c/dam/en/us/td/docs/voice_ip_comm/cust_contact/contact_center/crs/express_8_5/user/guide/uccx85dbschema.pdf
    Regards,
    Arundeep

  • How do you insert new records into multiple tables using the same unique primary key?

    I’ve created a PHP site and MySQL server using a free app called XAMPP.  I have successfully created a form in Dreamweaver that will write data to a (name) table in the SQL database.  Here’s my question: How do you write to two (or more) tables in the same database and pass the same primary key to both tables?  In the SQL database, I defined the first field as ID and set it as the primary key with auto update.  So, when you insert a new record, it creates a unique primary key for that record.  In my form, I’m capturing info that needs to be stored to two tables at the same time; a Name table and Address table. Since the Name and Address tables use the ID field as the primary key, I believe I will need to pass the ID value from the Name table to the insert of the Address table to insure they both have the same primary key, right?

    No. You probably need the primary key from one table to be a foreign key in the other tables. In any case, I believe you can use two methods to obtain the auto generated key. First with SQL:
    http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
    And the other using a PHP function:
    http://us3.php.net/mysql_insert_id

  • How to import a table from another oracle database ?

    Hi all ,
    i could like to use pl/sql to import one table from another oracle database server ?
    is it possible to do this ?
    A server B server
    table: test <------------------------> table : newtest
    the tns profile already configurated . the connection is ready .
    thanks a lot !
    Best Regards,
    Carlos

    if i don't have TEST table on server B whether COPY command will create this table on server B with the same structure ? If you specify CREATE as a clause the table will be created:
    SQL> help copy
    COPY
    COPY copies data from a query to a table in a local or remote
    database. COPY supports CHAR, DATE, LONG, NUMBER and VARCHAR2.
    COPY {FROM database | TO database | FROM database TO database}
                APPENDCREATE|INSERT|REPLACE} destination_table
                [(column, column, column, ...)] USING query
    where database has the following syntax:
         username[password]@connect_identifier

  • How can i convert the data from mutiple-table to the other database(MSSQL)?

    Dears,
    How can i convert the data from mutiple-table to the other database such as MS-SQL?
    I have a third party system based on MS-SQL 2000.
    Now we want to make a integration between SAP R/3(Oracle) and SQL server.
    When my user releases the purchase order in R/3, the application we coded will convert the releated data to the temp database on the SQL server.
    But i don't know which tools will help me reach the purpose.  BAPI, LSMW, IDoc... ???
    Would anybody tell me which way is better and how to do?
    Thanks a lot!
    Kevin Wang

    Hello Kevin,
    The question to use which method depend on your detail requirements. If you use BAPI, you need to find which Bapi can provide the data you want. Bapi normally use as a function called by external system. So you need to develop an external program like VB/Java to call this Bapi and move it to SQL. LSMW is use when you want to upload data from an external system to SAP. So it does not serve your requirement. Idoc can be use to export data to an external system. Again like Bapi, you need to find what Idoc can provide the data you want. However, it does not any programming from the external system. If I were you, based on your requirements, I think writing an Abap program that read the data you want and download it to NT/SQL server will be faster and easier.

  • How can i save the data from the Oracle database to my local directory

    How can i save the data from the Oracle database to my local directory instead Of saving the data file to the Directory created on the Oracle Server ?
    I require to design the Procedure which will pull the data from various tables and needs to store the data in the Client's local directory.

    Since SQL*PLUS runs on the client, you can use SQL*PLUS to spool data to your local drive.
    You could also use the database to write a a specified drive where all users have access to (mapped network drive, e.g.). I wouldn't recommend doing it that way, but it is sometimes useful when the files are created in some nightly batch run.

  • Error when installing 9.0.1.4.0 patch set for the Oracle Database Server.

    Hi to all.
    Currently, i am trying to install patches for portal server.
    The server OS is Sun Solaris 8.
    We are using Oracle9iAS.
    Now, we are installing 9.0.1.4.0 patch set for the Oracle Database Server.
    We managed to install the patch, but have problem with the Post Install Action.
    We managed to run
    -ALTER SYSTEM ENABLE RESTRICTED SESSION;
    -@rdbms/admin/catpatch.sql
    -ALTER SYSTEM DISABLE RESTRICTED SESSION;
    -CONNECT / AS SYSDBA
    -update obj$ set status=5 where type#=29 and owner#!=0;
    -commit;
    But, when we come to the next command, which is to shutdown, it gives us like
    this..
    SQL> update obj$ set status=5 where type#=29 and owner#!=0;
    1402 rows updated.
    SQL> commit;
    Commit complete.
    SQL> shutdown immediate
    Database closed.
    Database dismounted.
    ORA-00604: error occurred at recursive SQL level 1
    ORA-01219: database not open: queries allowed on fixed tables/views only
    We tried to startup the database..it gives us this error..
    SQL> startup
    ORA-01081: cannot start already-running ORACLE - shut it down first
    So, we tried to shutdown again..
    SQL> shutdown immediate
    ORA-01089: immediate shutdown in progress - no operations are permitted
    I been informed that this is maybe a Database problem related. Any ideas?
    Best Wishes,
    Rushdan Md Saad.

    Patchsets could be obtained (only) from http://metalink.oracle.com
    You need to have valid CSI for access.
    P.S: Sorry Werner, I didn't see you post.
    Message was edited by:
    Ivan Kartik

  • How to store image in the oracle database 10.2. using File Maker 10.

    Hi.,
    I want to store image, media file in the oracle database using File Maker as a front end.
    I connect Oracle using odbc from file maker. There are table and in that table there a column "pict" of blob type. but this column is not showing in the file maker.
    2. Here I can not change the data type of any column.
    Now how to store images in the oracle table using odbc or any other tool.
    Regards,
    Shyam

    I wrote an example for my students, you can find it here. It's using PHP as the front end but all you need to do is know how and leverage the stored procedures. All code is downloadable in zip files from the blog.
    http://blog.mclaughlinsoftware.com/php-programming/oracle-lob-processing/

  • Using Oracle Developer Suite 10g Without the Oracle Database

    I have never used Oracle, but have used MS SQL Server 7. I need to learn Forms. An Oracle salesperson suggested I download Oracle Developer Suite 10g (the demo product). It includes the Oracle Developer Suite (with Forms Developer), and many other programs.
    The salesperson said it includes a database server, but I suspect it does not. I only downloaded the package last night, and have begun to skim the documentation, but I see nothing that looks like a database server.
    In SQL Server 7, the database engine is run as a service and you create and manage your tables (do all the database admin stuff) using SQL Enterprise Manager.
    So, does this package include a database engine/server? Or must you also have the Oracle Database?
    I don't see a demo version of the Oracle Database - is there one?
    Thanks in advance for any help.

    Hi,
    The Developer Suite does not contain a demo version of the Oracle Database.
    You can download the database from this page:
    http://otn.oracle.com/software/products/oracle9i/index.html
    Vincent

  • Linking A LOT OF Tables in the same database

    Hi,
    Following is what I have been doing:
    THE FOLLOWING STEPS ARE DONE PERIODICALLY (like every 30 seconds):
    Get data from a database above a certain time stamp in a resultset
    Select some rows based on ceratin values of certain columsn in the resultset
    Change numbers to words and words to numbers in the selected rows using other tables in the same database
    Display this info in a table.
    Problem:
    My program is working but it consumes an enormous time when it has to link those selected rows with other tables to get corresponding values. Once I have made a resultset of selected rows, whats the fastest way to change row fields in the result set to corresponding values in the other table.
    Any iideas of even putting them in a table in an effecient manner would be greatly appreciated.

    Hi atlantisLoveAngel,
    I see you are new to these forums. In my opinion, it's not good practice to post exactly the same question to more than one forum, and you have posted this exact same question in the JDBC Forum.
    As you can see, a lot of the people who visit these forums do check more than one of them, so it doesn't really increase your chances of getting a reply when you post the same question to different forums (even if you change the subject slightly).
    I'm not sure if this will help you, but in case you haven't already seen it, perhaps the article entitled Christmas Tree Applications from the Swing Connection may be relevant?
    Good Luck,
    Avi.

  • THE DATA FROM THE ORACLE DATABASE VIEW DATA IS NOT REFERESHED AUTOMATICALLY

    THE DATA FROM THE ORACLE DATABASE VIEW DATA IS NOT REFERESHED AUTOMATICALLY IN OBIEE DASHBOARD(ANSWERS)
    UNLESS AND UNTILL I OPEN THE ORACLE BI ADMINISTRATOR TOOL AND DO UPDATE ALL ROWCOUNT AND THEN SAVE THE RPD.
    WHERE AS ORACLE DATABASE TABLE DATA IS AUTOMATICALLY REFRESHED.
    PLS SOMEONE HELP OUT IN THIS ISSUE.

    Check whether you have enable cache on that view?

Maybe you are looking for