Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly set utf8 encoding with jdbc and MySQL?

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 a System.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?

like image 270
pr0gma Avatar asked Nov 12 '15 10:11

pr0gma


1 Answers

Try to change your url like

url="jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=UTF-8" 

The & must be represented as &

like image 142
Rahul Tripathi Avatar answered Sep 19 '22 19:09

Rahul Tripathi