Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there a generic way to get sequence

 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avihai,
I don't follow. You want something that is both generic (works for all databases) and vendor specific (only works for one database) ?
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yoursequence.NEXTVAL for next

yoursequence.CURRVAL for current
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it will not work.

There is no sequence in MySql
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by atguva kohen:
There is no sequence in MySql

You're right. I was thinking of the auto-increment feature.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic