In the actual business there will be many through and the serial number splicing, form a user unique ID identification. Because this is used with the Oracle database, so the sequence of Oracle will be used, for demonstration convenience, so the dynamic obtained serial number is written to static. The specific source code is as follows:
Packagecom.evan.string;ImportJava.text.SimpleDateFormat; Public class barcodegeneratetest { Public Static void Main(string[] args) {String Dept ="0001";//sorting ID number intMax =202;//The next sequence of the current sequenceSimpleDateFormat SD =NewSimpleDateFormat ("YyMMdd"); String Day = Sd.format (NewJava.util.Date ()); String SPK = String.Format ("%05d", Max);//Barcode number generation rule: Sorting ID +999+ current date + next sequence of current sequenceString Barcode = Dept +"999"+ Day + SPK; SYSTEM.OUT.PRINTLN (barcode);//000199915050700202 /** Front 0 The bar code number is enforced to 18 bits, in Excel import, you may encounter, because the Excel bar code display is 000199915050700202 but passed to the background after it becomes 199915050700202, three 0 automatically will be gone. can be resolved with a forced complement zero. */String Sglcheckid ="123456789"; String result = String.Format ("%018d", integer.valueof (Sglcheckid)); SYSTEM.OUT.PRINTLN (result); }}
However, there may be a problem with this, that is, when the sequence grows to its maximum value on the same day, the sequence restarts from the minimum value, which results in a repetition of the bar code.
There are currently two possible solutions:
1, requires the business unit, currently can import up to 100,000 data. (That's what I'm doing now.)
2, the bar code number generation rule change, increase two order of magnitude.
Java generates barcode number source code