HI, I have a postgres database with latin1 charset, and a table "user". I need to insert the name of the users using a prepared statement in java
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;
}
The problem is when user.getName() and user.getEmail() contains characters with accents like è,ò, and so on, the table store weird characters. How can save the right characters sequence from java utf-16 to postgres latin1 charset encoding?