JDBC Connection: Retrieve auto-increment id
Jerony_2338
Posted messages
9
Status
Member
-
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
-
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.-
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.- 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.
-
-