If you do not want to operate the database, here is a way to try, directly on the code:
PackageCom.seawin.common.util.convert;ImportJava.text.DecimalFormat;ImportJava.text.SimpleDateFormat;Importjava.util.Date; Public classPrimarygenerater {Private StaticString serial_number = "0001" ; Private StaticPrimarygenerater Primarygenerater =NULL; PrivatePrimarygenerater () {}/*** Get a single implementation of Primarygenerater * *@return */ Public StaticPrimarygenerater getinstance () {if(Primarygenerater = =NULL) { synchronized(Primarygenerater.class) { if(Primarygenerater = =NULL) {Primarygenerater=NewPrimarygenerater (); } } } returnPrimarygenerater; } /*** Generated date + random number of serial number **/ Publicstring Getnumberforpk () {string id=""; SimpleDateFormat SF=NewSimpleDateFormat ("Yyyymmddhhmmss"); String Temp= Sf.format (NewDate ()); intRandom= (int) (Math.random () *10000); ID=temp+Random; returnID; } /*** hhtg+ Month +8+0001 * Monthly starting from 0001 count **/ Public Static synchronizedstring GetNumber (String thiscode) {string id=NULL; Date Date=NewDate (); SimpleDateFormat Formatter=NewSimpleDateFormat ("Yymm"); String Thisdata= Thiscode.substring (4, 8); //The judgment is that the last business number that you have taken out of your data is not the current month. if(!Formatter.format (date). Equals (Thisdata)) {System.out.println ("The New January"); Thisdata=Formatter.format (date); //if it's a new January, it's going to become 0001.id = "HHTG" + thisdata + "80001"; }Else{System.out.println (Month); DecimalFormat DF=NewDecimalFormat ("0000"); //It's not the new January, it's cumulative.id = "HHTG" + formatter.format (date) + "8" + df.format (1 + integer.parseint (thiscode.substring (9, 13))); } returnID; } Public Static voidMain (string[] args) {/*** HHTG170980001 * HH company abbreviation + TG Business Type + month + 8 department + 0001 * **/String Sno= "HHTG170980001"; System.out.println (GetNumber (SNO)); } }
The results are as follows:
The results of the month replaced are as follows:
Java generates self-increment serial number and re-clear 0 count from the first day of each month (original)