I have the following issue. The java resultset is not showing Unicode (Chinese) characters, but showing all other characters. I am sure all characters are stored/showing properly from in Microsoft SQL Server (as nvarchar).
So it seems to be a retrieving issue. Here is the code:
protected String getStringValueNoNulls(ResultSet rs, String colName) {
String ret = rs.getString(colName);
ret = new String(ret.getBytes(), "UTF8");
System.out.println(ret);
... Output for the print statement:
SO (SO in DB)
??? (张先生 in DB)
??????9999 ( 建国门外大街9999 in DB)
?? (北京 in DB)
100010 (100010 in DB)
It showing all English/ascii characters but not the Chinese characters. I noticed the number of Chinese characters is equal to the question marks it replaces with.
I have tried before just plain getString(), and now doing getBytes() for conversion both producing the same results.
Is something I am missing, or is it maybe an issue with driver? Please help.
----------------I Just added this as my connection, didn't help:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://127.0.0.1:1433;database=myDB;user=myuser;password=myPass;useUnicode=true;characterEncoding=UTF-8";
Connection con = DriverManager.getConnection(connectionUrl);
Still getting the same questions marks for the Chinese characters.
Regards.