mercredi 26 juillet 2017

Generating ID randomly and persisting it in Java efficiently

I need to generate a number of length 12, say variable finalId. Out of those 12 digits, 5 digits are to be taken from another value, say partialid1.

Now finalId = partialId1(5 - digits)+ partialId2(7 digits).

I need to generate partialid2 randomly, where I can use Random class of Java.

Finally i have to insert this finalId in Database, as a Primary key.

So to make sure that newly generated finalId is not existing in Oracle Database, I need to query Oracle Database as well.

Is there any efficient way other than the one i have mentioned above to generate Id in Java and check in database before persisting it?




Aucun commentaire:

Enregistrer un commentaire