• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Generating number sequence ,

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.
-mark
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Harish Maridi
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!