javadatabasejdbcutf-8character-encoding

Java PreparedStatement UTF-8 character problem


I have a prepared statement:

PreparedStatement st;

and at my code i try to use st.setString method.

st.setString(1, userName);

Value of userName is şakça. setString methods changes 'şakça' to '?akça'. It doesnt recognize UTF-8 characters. How can i solve this problem?

Thanks.


Solution

  • The number of ways this can get screwed up is actually quite impressive. If you're using MySQL, try adding a characterEncoding=UTF-8 parameter to the end of your JDBC connection URL:

    jdbc:mysql://server/database?characterEncoding=UTF-8

    You should also check that the table / column character set is UTF-8.