1
votes

I use the below java code to insert data in 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();

}

On inserting text like mamá the data stored in mysql is mamá What should I do to correct this ? So far 1. I have updated the table encoding type to UTF-8 2. updated the connectionstring like jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8

Please help

1
as your output indicates, the á is stored correctly as UTF-8 - in a two -byte sequence. Please show the code you use to read/display that information - the error is most likely there. - Jan
I can see the incorrect text in database. The error is while inserting not while reading - coder310

1 Answers

0
votes

Resolved it using below code ps.setString(4, new String("test".getBytes("ISO-8859-1"), "UTF-8"));