0

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.

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by __avd
0

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

0

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);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.