Java generates barcode number source code

Source: Internet
Author: User
Tags unique id

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.