This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
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: 1624
    
  13

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.
 
jQuery in Action, 2nd edition
 
subject: create auto increment id for oracle database
 
Similar Threads
how to call a javabean method from jsp using setproperty
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
How to edit database table in jsf
java.sql.SQLException: Invalid column index
A very little jsf bean question