• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Auto Increment ID Field Table in the Oracle Database

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

and 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?
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OKay, the table into which I am trying to insert new records has a sequence: dhsinfo_content-grp_seq

The DBA has done that part. I am worrying about the Java part. To give you an example the origin of my confusion, I have:


All the parameters of the updateContent() methods have known values. Where in the code we use that sequence key for INSERT? Do I insert new record this way:


[edited to fix page allignment]
[ September 30, 2004: Message edited by: Jeanne Boyarsky ]
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


From your code section above, you try to get the sequence value from dual in the insert statement.

You don't need the "FROM DUAL" above...

If you want to see the next value of the sequence you can
SELECT <someseq>.NEXTVAL FROM DUAL

If you want to use the sequence in a query, you can.. if you have a table called customers... this would work as well....

SELECT cust.name_first, cust.name_last, <someseq>.NEXTVAL
FROM customers cust
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean this is what I should do:

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me make sure that I am doing it right.

In my case,

1. the table name in the Oracle database is DHSInfoContentGroup
2. ID is the column name of that table for auto increment
3. dhsinfo_content_grp_seq has been taken care of by DBA

Therefore, the code should look like:
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am very confused. The source of the confusion is switching from the MySQL database to the Oracle database. If I use the Oracle database:


What should I do with my Java code in database operation?
 
Colin Fletcher
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[B]
Do you mean this is what I should do:

code:

[/B]



Exactly - for Oracle
 
Colin Fletcher
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For MySQL you would have to

1. remove the field from the query
2. change the field in the table to auto increment

-C
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about the statement:

or this is the correct way to do:
 
Colin Fletcher
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The second one :-)
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. It works.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic