File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 2296

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:
subject: create auto increment id for oracle database
It's not a secret anymore!