How to properly set utf8 encoding with jdbc and MySQL?
10,257
Try to change your url like
url="jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=UTF-8"
The &
must be represented as &
Related videos on Youtube
Author by
pr0gma
Updated on June 18, 2022Comments
-
pr0gma almost 2 years
JDBC and MySQL work just fine in my project except when it comes down to accented characters. This is the URL I use to access the database:
jdbc:mysql://localhost:3306/dbname?useUnicode=yes&characterEncoding=UTF-8
Suppose a
resultSet = preparedStatement.executeQuery()
, and then aSystem.out.println(resultSet.getString("text_with_accents"));
. What's stored in the database isàèìòù
(note that I've already set the right encoding in the database and all its tables), but what I get is?????
.Is there a way to fix this?
-
Rahul Tripathi over 8 years@pr0gma:- Can you check your my.cnf and see if your file has
[client] default-character-set=utf8 [mysql] default-character-set=utf8
present? -
pr0gma over 8 yearsI have no my.cnf. Should I create one? If so, where?
-
Rahul Tripathi over 8 years@pr0gma:- It should be present. You can refer this: stackoverflow.com/questions/4292769/… to get its location
-
pr0gma over 8 yearsFound the my.ini. Double checked, the option was already set in both the client and mysql section.
-
Rick James over 5 years
characterEncoding=utf8
-->characterEncoding=UTF-8
.