File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Generating number sequence , Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Generating number sequence ," Watch "Generating number sequence ," New topic

Generating number sequence ,

Harish Maridi
Ranch Hand

Joined: May 20, 2008
Posts: 60

I am using struts framework, So I am posting this topic here.

My application insert a record in DB, while inserting it should generate a number sequence for that record.
for example: today I am inserting first record, the sequence should be 2008060001 (YYYYMM0001), second record 2008060002.
I am able to get up to YYYYMM, but the sequence I am unable to get it.
Can any body suggest me about it.
Thanks in advance.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd suggest you create a table in your database with two rows: Year_month and seq_no. Whenever you generate a new record for your other table, look for a record in this table for the given year/month. If there is no record, insert a record for this year/month with a sequence number of "1" and return 1 as the sequence number. If there is a record, get the sequence number, add 1 to it, update the table with the new sequence number, and return the incremented sequence number to be used by the other table.
[ June 17, 2008: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
Harish Maridi
Ranch Hand

Joined: May 20, 2008
Posts: 60
Thanks ....
I agree. Here's the link:
subject: Generating number sequence ,
It's not a secret anymore!