I am having issues with char encoding when performing an insert into a mysql table. The table field I am focused on have the following properties:
Collation:utf8_general_ci varchar(255)
The problem occurs with chinese and foreign characters. I tried using a callablestatement to call a stored procedure but it does not work as the entry appears as follows:
?????
I debugged and found that the callablestatement charencoding property has this value;
Cp1252
I have not found a way to change this. I tried setting the values I insert to NVARCHAR but that too is not working. A suggestion to try the JDBCTemplate to do the insert did not work as well:
Object[] params = new Object[] { Num, Name, Link,type,siteid,GreetingController.StreamID };
int[] types = new int[] { Types.NVARCHAR, Types.NVARCHAR, Types.NVARCHAR,Types.INTEGER,Types.NVARCHAR, Types.NVARCHAR };
recordsAffected= jdbcTemplateObject.update( sql, params, types);
and the callablestatement code:
Connection conn = DriverManager.getConnection(connectionUrl,info);
CallableStatement cstmnt = conn.prepareCall("{ call putNewPage(?,?,?,?,?,?) }");
cstmnt.setString(1, Num);
cstmnt.setString(2, Name);
cstmnt.setString(3, Link);
cstmnt.setInt(4, type);
cstmnt.setString(5, siteid);
cstmnt.setString(6, GreetingController.StreamID);
This is frustrating. I know .NET has it as a default when working with SQL inserts to have encoding UTF-8. Any help appreciated,
Try to include the Encoding in connection string as well like this
jdbc:mysql://localhost/some_db?useUnicode=yes&characterEncoding=UTF-8