wood burning stoves 2.0*
The moose likes JDBC and the fly likes create auto increment id for oracle database  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "create auto increment id for oracle database  " Watch "create auto increment id for oracle database  " New topic

create auto increment id for oracle database

Ahmad Shekha

Joined: Oct 10, 2013
Posts: 1
hi everyone :
I want to create auto increment id in oracle 11g in preparedStatement , I realize is no auto-increment in oracle

this is my code

but I have this run time error

note: I am do not use trigger and I do not know how I can use it
please help i'm beginner in programming
chris webster

Joined: Mar 01, 2009
Posts: 1476

In Oracle you should define a sequence in your database schema e.g.


Then you can get the next value off this sequence in your SQL INSERT statement:

INSERT INTO employee (id, firstname, ...) VALUES(emp_id_seq.NEXTVAL, ?,....)

There are other ways to use a sequence e.g. set the ID via a trigger, or if you're using an ORM you can tell it to use the sequence for generating IDs for this table. But right now this is probably the simplest approach.

Oracle sequence values are guaranteed to be unique, and there are various additional options e.g. for caching sets of sequence values, specifying the incremental step, re-cycle point etc.

No more Blub for me, thank you, Vicar.
I agree. Here's the link: http://aspose.com/file-tools
subject: create auto increment id for oracle database
Similar Threads
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
A very little jsf bean question
how to call a javabean method from jsp using setproperty
How to edit database table in jsf
java.sql.SQLException: Invalid column index