嗨,我有一个带latin1字符集的postgres数据库和一个表“用户”。我需要用准备好的语句在java中插入用户名将java utf-16字符串插入到postgres字符字段中
boolean success = false;
String query = "INSERT INTO public.user (name,email) VALUES(?,?)";
try {
PreparedStatement ps;
ps = db.prepareStatement(query);
ps.setString(1, user.getName());
ps.setString(2, user.getEmail());
if (ps.executeUpdate() != 0)
success = true;
ps.close();
} catch (SQLException ex) {
} finally {
return success;
}
问题是,当user.getName()和user.getEmail()中包含像电子口音,O等字符,表存储怪异的字符。如何将正确的字符序列从java utf-16保存到postgres latin1字符集编码?