Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2013
    Location
    Accra,Ghana
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Generating a unique Serial Key in java

    i have a table ITEMS which has these columns and data
    Code:
    Description = Lands & Building 
    Description_Code= LB(001)
    
    i also have another table BRANCHES which has these columns and data
    Branch_Area=Labone
    Branch_Code=LB(001)
    i want to generate my serial number based on a default FC/ +Branch_Code/+Description_Code
    example is FC/LB/100/LB/001
    Any directions or help will be appreciated THANK YOU

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,911
    Thanks
    15
    Thanked 227 Times in 227 Posts
    Strictly speaking, you want to generate a unique identifier, which you can probably do just by hashing that combination with any number of algorithms. A serial number is a consecutive number assigned in time order.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #3
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    import java.util.Date;
    
    public class IdUniqueHelper {
    	private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";// "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    	private static final long BASE = 36;
    	private static final String DIGIT = "0123456789";
    
    	public static String encode(long num) {
    		StringBuilder sb = new StringBuilder();
    
    		while (num > 0) {
    			sb.append(ALPHABET.charAt((int) (num % BASE)));
    			num /= BASE;
    		}
    
    		return sb.reverse().toString();
    	}
    
    	public static String getId() {
    		Date date = new Date();
    		String id = encode(date.getTime());
    		return id;
    	}
    	
    }
    Use date time to generate is a way.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •