uniqueidentifier in Sql Server database - how to generate in Java environment?
-
06-09-2019 - |
Question
I have a database table that uses Sql Server 2005's uniqueidentifier column.
I know how to create GUIDs in C#...
string newid = System.Guid.NewGuid().ToString();
However, the application that is inserting into this database is running Java.
Is there a way to generate Sql-Server-compatible GUIDs using Java code?
(NOTE: generating the GUIDs on the Sql Server side is not an option in this case)
Is this - http://johannburkard.de/software/uuid/ - equivalent to the C# version?
Solution
Why not simply use the built in class java.util.UUID, assuming you are using at least Java 1.5
OTHER TIPS
The code you linked ought to work fine. For kicks, here's another implementation with some good documentation to boot. http://jug.safehaus.org/Home
GUID's are a pretty well defined phenomenon, typically involving a unique machine identifier and the current time and then a bunch of randomness. Anybody who has taken the time to write a GUID library ought to have spent enough time on it to be much better at it than you or I are, so using a library is the right choice. The code I linked has a bunch of links to the IETF specs etc, so I think that's a pretty good sign that they did their due diligence.
See http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt