3

If I have this query from java:

String query="insert into user (..., name, ...) values (..., 'à', ...)";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/Spinning?user=root");
PreparedStatement prest = con.prepareStatement(query);
prest.executeUpdate();

In the db I will have a strange character: a diamond with a question mark inside.

Is there any solution to this problem?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Martina
  • 1,852
  • 8
  • 41
  • 78

2 Answers2

3

Change your connection url to the following:

jdbc:mysql://localhost/Spinning?user=root&useUnicode=true&characterEncoding=utf8
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
1
  1. Verify the character set you are using in MySQL DB. You can try "SHOW CREATE TABLE xxxx" to print the table DDL with charset being used.
  2. Verify the character set you are using in JDBC driver. If using MySQL ConnectorJ, you can set charset in the JDBC url.
Bimalesh Jha
  • 1,464
  • 9
  • 17