File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "create auto increment id for oracle database  " Watch "create auto increment id for oracle database  " New topic
Author

create auto increment id for oracle database

Ahmad Shekha
Greenhorn

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
Bartender

Joined: Mar 01, 2009
Posts: 1846
    
  16

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

CREATE SEQUENCE emp_id_seq;

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