hi,
actually i want to set a order id by automatically...
example:

oderId : GB0001

and it will increase automatically each time some one make order.

Recommended Answers

All 2 Replies

If I understand correctly (if I don't you should have provided a better explanation) you want to insert a new order in a database?
If yes there is an SQL command when you create a table where you set the Primary Key to be auto increment so when a new row is inserted the key will have a sequence number. Try to search how to create a "sequence" and how to get the next value at an SQL forum or at the internet.
If you want the String "GB" next to the number, then create the table like normal with a primary key, then declare the "sequence" and whenever you want to insert write a select that gets the next number and add to it the String "GB". Then use this value as order ID.

Of course everything is based on assuming that this was what you wanted to know. If I am wrong provide better explanation.
If I was right but you don't understand what I am saying it's my fault. Ask for better explanation at an SQL forum

Try to understand this code - It's string operation.

String old="GB0001"; // Assume that this value is come from Database
       int no=Integer.parseInt(old.substring(2,6));
       no++;
       String format="%04d";
       String newstr="GB" + String.format(format,no);
       System.out.println(newstr);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.