How to use Unicode, JDBC and Solid Database
It is not always so straightforward to use Unicode throughout your application layers. Let’s say that your Java application’s default character encoding for file I/O operations, JDBC requests and so on is Unicode. In other words you start you Java application on command line for example with:
java -Dfile.encoding=UTF-8 If your Solid Database’s string types are not defined as Unicode, there is a little problem.
In the Java JDBC API tutorial it says:
JDBC driver implementations are expected to automatically convert the Java programming language unicode encoding of strings and characters to and from the character encoding of the database being accessed.
So, basically JDBC driver should do the conversion between application’s and database’s character encoding. But in the Solid Programmers Guide it says:
To convert Java applications to support Unicode, the string columns in the database engine need to be redefined with Unicode data types.
Actually Solid’s JDBC driver won’t even return strings in the same character encoding as they are defined in the database, but it mixes all “special characters” wrong. There aren’t any proprietary parameters you could use on the JDBC connection string to choose the character encoding. So, only working solution is to somehow convert strings in a Solid database in the SQL queries before the JDBC driver returns them. Luckily Solid’s SQL implements CAST function. You can for example cast VARCHAR to WVARCHAR which is Unicode variable-length character string. Here is an example:
SELECT CAST(name AS WVARCHAR) name FROM... And it works like a charm.