Reputation: 641
Continuing my previous question https://stackoverflow.com/questions/21060720/jsp-upload-file-with-utf-8-encoding
I discovered that when i do:
String url = "jdbc:mysql://localhost:3306/crm2?useUnicode=yes&characterEncoding=UTF-8";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
connection = DriverManager.getConnection (url, MY_USERNAME, MY_PASSWORD);
PreparedStatement pst = connection.prepareStatement(sql);
.
.
.
pst.setString(1, customer.getFullName());
.
.
.
pst.executeUpdate();
I got the following SQL exception:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(
name
= '?…?±?ˆ?§?†'
As you can see i mentioned in the connection string too use encoding utf-8! looks like i have to do something else in the PST to insure using UTF-8?
Thanks
Upvotes: 1
Views: 2374
Reputation: 123409
When reading and writing to a database with UTF-8 data it is important that the Java source code file be encoded as UTF-8. Otherwise, strange things can happen when we start manipulating strings that we receive from (or send to) the database.
Upvotes: 2