• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unique sequence number  RSS feed

 
Suchi Choudhary
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to generate a unique sequence number in java that should be a int.
I need this number in my SMPP module.

i can generate this in String as UUID.randomUUID().toString();
and in long as Calendar.getInstance().getTimeInMillis();

but unable to do that for int. Can anybody help me for this???
 
salvin francis
Bartender
Posts: 1653
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
salvin francis
Bartender
Posts: 1653
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or more simpler ... you may convert the long milliseconds of calendar into int.
 
Suchi Choudhary
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is what i have tried initially but the error which i got is that when i restarted the server.
after restart, the number again starts with the same number making duplicate entries in the database.

we can use the number again if it is 24 hours old i.e we can use a number once in a day as sequence number.
the things starts when i restarted the server twice or thrice a day.

Any help?
 
Suchi Choudhary
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or more simpler ... you may convert the long milliseconds of calendar into int.



you can try this one, it throws NumberFormatException as we are trying to convert a long into int.
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it an unique sequential number or an unique random number? If it is an unique sequential number and you are using database then whats wrong in fetching the last sequence number from database and add 1 the that.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do a search; there have been quite a lot of similar questions here and in beginners'.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!