I think MySQL does not consider this a valid UTF8 text. I tried pasting into a test table with the same column definition (the connection to the mysql client was also UTF8), and although it was pasting, the data I received with the MySQL CLI client as well as JDBC did not display the values โโcorrectly. To make sure that UTF8 is working correctly, I inserted instead of "o" for obama "รถ":
johan@maiden:~$ mysql -vvv test < insert.sql -------------- insert into utf8_test values(_utf8 "walmart รถbama ๐ฝ๐") -------------- Query OK, 1 row affected, 1 warning (0.12 sec) johan@maiden:~$ file insert.sql insert.sql: UTF-8 Unicode text
Small Java application for testing:
package test.sql; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; public class Test { public static void main(String[] args) { System.out.println("test string=" + "walmart รถbama ๐ฝ๐"); String url = "jdbc:mysql://hostname/test?useUnicode=true&characterEncoding=UTF-8"; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection c = DriverManager.getConnection(url, "username", "password"); PreparedStatement p = c.prepareStatement("select * from utf8_test"); p.execute(); ResultSet rs = p.getResultSet(); while (!rs.isLast()) { rs.next(); String retrieved = rs.getString(1); System.out.println("retrieved=\"" + retrieved + "\""); } } catch (Exception e) { e.printStackTrace(); } } }
Output:
johan@appel:~/workspaces/java/javatest/bin$ java test.sql.Test test string=walmart รถbama ๐ฝ๐ retrieved="walmart รถbama "
In addition, I tried the same insert with a JDBC connection, and this led to the same exception that you get. I believe this is a MySQL error. Maybe there is already an error message there.
Friek Dec 6 2018-12-12T00: 12Z
source share