aspose file tools*
The moose likes JDBC and the fly likes about add the id number according the existing sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "about add the id number according the existing sequence" Watch "about add the id number according the existing sequence" New topic
Author

about add the id number according the existing sequence

Jian Zhang
Greenhorn

Joined: Aug 30, 2003
Posts: 20
I have an existing sequence called TOPICSEQ in the database(oracle), there is a table called t_topic whose id is incremented using this TOPICSEQ. The detail of this seq is created like following
CREATE SEQUENCE TOPICSEQ
INCREMENT BY 1
START WITH 1001 MAXVALUE 9999 MINVALUE 1
NOCYCLE CACHE 20 NOORDER;
It works fine when populating the db with scripts, but when inserting the data using the format like this:
String insertTopic="INSERT INTO T_TOPIC VALUES (TOPICSEQ.NEXTVAL,?,0,'unchecked')";
the last topicID is 1006 in the table before I insert the data , after the insertion, the ID becomes 1021. I don't know what the hell it is and I thought it should follow the sequence since I specified the name of the sequence.

Please, just a week I have to submit my project. Any idea will be appreciated. Thanks a lot!
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30910
    
158

Jian,
The "cache 20" tells oracle to reserve groups of 20 ids at a time. When your script ran, it probably got allocated 1000-1020. Then, when you ran using a different client (jdbc) it got from the next available group. Thus 1021.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about add the id number according the existing sequence