java - char encoding doing mysql insert with callablestatement or jdbctemplate -
i having issues char encoding when performing insert mysql table. table field focused on have following properties:
collation:utf8_general_ci varchar(255)
the problem occurs chinese , foreign characters. tried using callablestatement call stored procedure not work entry appears follows:
?????
i debugged , found callablestatement charencoding property has value;
cp1252
i have not found way change this. tried setting values insert nvarchar not working. suggestion try jdbctemplate insert did not work 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 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 frustrating. know .net has default when working sql inserts have encoding utf-8. appreciated,
try include encoding in connection string jdbc:mysql://localhost/some_db?useunicode=yes&characterencoding=utf-8
Comments
Post a Comment