Discussion: Generating Unique ID's in combinations of numbers and alphabets

Member

5 messages from 5 displayed.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
And can't you just use numeric primary keys and then prefix them in your application with some product code? Generating unique string IDs is quite a problem, mainly if they should be incremented. Consider you happen to have multiple requests at the same time, you check what is the last ID, generate a new one but another thread of your application has just done the same so you end up with 2 same IDs.
If you really need GUIDs, I'd create a trigger and let the database itself to assign them. I tried to find some solution for you but it's apparently not a common approach so you'd have to come up with a solution by yourself.
There is the uuid() MySQL function which generates something like this:
aab5d5fd-70c1-11e5-a4fb-b026b977eb28
Maybe you could use this or go with prefixed numeric IDs.
i use the code in the attached file.
to give me ID's Starting from 10000,10001,10002etc
but I want it to be like ADM10000,ADM10001
thanks.
//CODE
int bid=9999
public void idincrement() {
String url = "jdbc:mysql://localhost:3306/";
String dbName = "opma";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "";
try {
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url + dbName, userName, password);
stmt = con.createStatement();
stmt = con.createStatement();
ResultSet res = stmt.executeQuery("select * from addstudent");
while (res.next()) {
bid = res.getInt(1);
}
} catch (ClassNotFoundException | InstantiationException |
IllegalAccessException | SQLException e) {
JOptionPane.showMessageDialog(null, "the error is" + e.getMessage());
//System.out.println(e.getMessage());
}
bid = bid + 1;
sid.setText(Integer.toString(bid));
}
Don't code this manually, just set the autoincrement value to 1000 to your database:
ALTER TABLE users AUTO_INCREMENT=1001;
5 messages from 5 displayed.