我使用下面的java代码在mysql中插入数据
private Long insertMFPatient() {
KeyHolder keyHolder = new GeneratedKeyHolder();
jdbcTemplate.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(
Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(
"insert into test(firstname, lastname) values(?,?)",
new String[] { "changeid" });
ps.setString(1, "mamá");
ps.setString(2, "test2");
return ps;
}
}, keyHolder);
return keyHolder.getKey().longValue();
}
在插入像mamá这样的文本时,存储在mysql中的数据是妈妈 我该怎么做才能纠正这个问题? 至今 1.我已将表格编码类型更新为UTF-8 2.更新了连接字符串,如jdbc:mysql:// localhost:3306 / test?useUnicode = true& characterEncoding = UTF-8
请帮忙
答案 0 :(得分:0)
使用以下代码解决它 ps.setString(4,new String(“test”.getBytes(“ISO-8859-1”),“UTF-8”));