-1

I have developed a sample registration application. Now, my requirement is to generate a unique registration ID for the registered customers and insert that unique ID into the database. How to generate unique ID once the customer is registered?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alekhya
  • 9
  • 4

1 Answers1

0

java.util.UUID class randomUUID() method always give you unique id

Example :

import java.util.UUID;

    public class GenerateUUID {

      public static final void main(String... aArgs){
        //generate random UUIDs
        UUID idOne = UUID.randomUUID();
        UUID idTwo = UUID.randomUUID();
        log("UUID One: " + idOne);
        log("UUID Two: " + idTwo);
      }

      private static void log(Object aObject){
        System.out.println( String.valueOf(aObject) );
      }
    } 
atish shimpi
  • 4,873
  • 2
  • 32
  • 50
  • The unique ID. should be the combination of customer name. In the sense, first three letters of the customer name concating the company code. assume customer name is Ravi and company code is 1000001. then unique id should be rav1000001, if second customer is Ramu then his unique ID should be ram1000002. – Alekhya Jan 06 '15 at 05:16
  • 1
    If you want to create your custom Unique id then use `name.substring(0,2)+compaycode`, but I will fail when customer having same name and they are in same company. – atish shimpi Jan 06 '15 at 06:24
  • 1
    @Alekhya, those sorts of requirements belong in your initial question not in a comment after someone has spent time trying to answer your very broad request. – William Price Jan 06 '15 at 06:50