I'm using a JDBC PreparedStatement
directly from a Java application, something like:
stmt = connection.prepareStatement("SELECT mycolumn FROM mytable WHERE ...");
...
String mycolumn = stmt.getString("mycolumn");
The type of mycolumn
is UNIQUEIDENTIFIER
. This is a Microsoft SQL Server-supported binary data type of 128 bits, representing a UUID, which gets automatically converted to string.
The problem is, I would like to retrieve this string in lowercase. When using C# with Entity Framework, the string is always lowercase (as shown in the documentation ). However, in JDBC (using the latest JDBC driver from Microsoft) it always comes out in uppercase.
I can work around this, e.g.
connection.prepareStatement("SELECT lower(mycolumn) FROM mytable WHERE ...")
but that makes it less efficient (it's a performance-critical application) because the data comes in as a string (36 bytes + overhead) instead of a 16-byte binary number.
Another workaround:
stmt.getString("mycolumn").toLowercase()
but that is more processing than necessary, as the binary number first gets converted to uppercase, and then gets converted to lowercase.
Is there an option that makes the getString
method directly return a lowercase string?
1条答案
按热度按时间zqdjd7g91#
Have you considered
getBytes
instead ofgetString
? If you're not happy with how Java converts a UNIQUEIDENTIFER to a string, provide your own implementation.