0

Okay ill try to keep this short. I have Java web site and MySQL Database. Everything uses UTF-8 charset. Problem is that if i try to insert Lithuanian letters into database all letters like "ą č ę ė į ų ū" are converted into question marks.

Insert code:
public static boolean addUser(UserEntity userEntity) {
    Connection con = getDataBaseConnection();
    PreparedStatement statement = null;
    try {
        if (userEntity.isIsActive()) {
            booleanInt = 1;
        } else {
            booleanInt = 0;
        }
        if (con != null && !con.isClosed()) {
            statement = con.prepareStatement("INSERT INTO users (login,"
                    + " firstName,"
                    + " lastName,"
                    + " personalId,"
                    + " isActive,"
                    + " password)"
                    + "VALUES(?,?,?,?,?,?)");
            statement.setString(1, userEntity.getLogin());
            statement.setString(2, userEntity.getFirstName());
            statement.setString(3, userEntity.getLastName());
            statement.setString(4, userEntity.getPersonalId());
            statement.setInt(5, booleanInt);
            statement.setString(6, userEntity.getPassword());
            System.out.println(statement.toString());
           //statement.executeUpdate();
            return statement.execute();
        }
    } catch (Exception ex) {
       System.out.println(ex);
    } finally {
        closeConnection(con);
        return false;
    }

If we print out for userEntity.getLogin it prints out everything with letters as it should be. Lets say its Mažeikiai. If we print out prepared SQL statement it will be replaced. Java is set to work with UTF-8, GlassFish, database also.

Mindaugas
  • 1
  • 1
  • Is the database table / column using UTF8 too? It looks like a duplicate: http://stackoverflow.com/questions/3828818/java-preparedstatement-utf-8-character-problem – Balint Bako Jun 20 '13 at 07:18
  • possible duplicate of [Java lithuanian letters](http://stackoverflow.com/questions/7222475/java-lithuanian-letters) – Raedwald Jan 07 '14 at 13:11

2 Answers2

0

Try create connection like this:

con = DriverManager.getConnection("jdbc:mysql:///dbname?useUnicode=true&characterEncoding=utf-8", "user", "pass");
jtomaszk
  • 5,583
  • 2
  • 26
  • 39
0

How are you viewing the data that you have inserted?

It is possible that the console that you are printing to is not supporting a UTF-8 character set.

Java Devil
  • 9,835
  • 7
  • 30
  • 44