JDBC Connection: Retrieve auto-increment id

Jerony_2338 Posted messages 9 Status Member -  
Jerony_2338 Posted messages 9 Status Member -
I'm sorry, but I can only provide translations. Please provide the text you need to be translated.

1 answer

KX Posted messages 19031 Status Moderator 3 020
 
Hello,

You can generate a UUID with Java, insert it into the database, and use it to retrieve the auto-increment.

See: https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/util/UUID.html
--
Trust does not exclude control.
0
Jerony_2338 Posted messages 9 Status Member
 
Hello,

Thank you for your intervention. I took a quick look, and if I understood correctly, it's like I'm generating 2 keys (the generator's key + the UUID key) only to end up retrieving just one of them. From what I have seen, the key generated by the UUID is 4 times larger (128 bits) than a primitive integer type, so I question the legitimacy of its use, especially in my "context." The exercise I was trying to do was more about directly retrieving the generator's ID from the database and sending it back. However, I'm not sure if there are any methods in the UUID class that allow, among other things, the direct retrieval of the generator's ID, as if it works like a ResultSet. Thank you again for the time you dedicated.
0
KX Posted messages 19031 Status Moderator 3 020 > Jerony_2338 Posted messages 9 Status Member
 
To retrieve the ID generated in the database, the solution you have already proposed is Statement.RETURN_GENERATED_KEYS, but if it is not applicable to Firebird, we need to find workarounds that will inevitably be a degraded solution, for example with a second ID.

And yes, the UUID is very large, but it is unique among all other UUIDs in the world, whereas your auto-incremented ID is only unique to your database instance.
0
Jerony_2338 Posted messages 9 Status Member
 
Thank you for your input. Yes, I do suspect that in a "Real" application context (which is not yet the case), using UUIDs proves to be more efficient than a simple auto_increment. However, thank you for the clarification.
0