wood burning stoves 2.0*
The moose likes JDBC and the fly likes Is there a generic way to get sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Is there a generic way to get sequence" Watch "Is there a generic way to get sequence" New topic
Author

Is there a generic way to get sequence

avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
Hey,

I need a counter that will not initialized when my sever restarted, so i decide to write sequence in the data base for this.
My question is there a generic (for any vendor) way to get next id?

Thank you
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30972
    
159

Avihai,
I don't follow. You want something that is both generic (works for all databases) and vendor specific (only works for one database) ?


[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
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
yoursequence.NEXTVAL for next

yoursequence.CURRVAL for current
avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
Currently , i neeed to support in MySql and Oracle.
The sequence will be writed vendor specific, my question is regarded query the sequence from my java application.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30972
    
159

Originally posted by avihai marchiano:
Currently , i neeed to support in MySql and Oracle.
The sequence will be writed vendor specific, my question is regarded query the sequence from my java application.

I see. If you only need to support these two databases (as opposed to every database there is), Paul's code will work.
atguva kohen
Greenhorn

Joined: Jan 01, 2008
Posts: 2
No it will not work.

There is no sequence in MySql
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30972
    
159

Originally posted by atguva kohen:
There is no sequence in MySql

You're right. I was thinking of the auto-increment feature.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there a generic way to get sequence