I am having a bit of trouble collating Arabic characters into MySQL database using Java.
I am using utf8 for all my tables and my database. Here are some screen shots from Mysql Workbench:
The String that I tried to collate is: عماد
It's worth mentioning that Arabic is coded over 2 bytes, so this is clearly not an issue of regular utf8 not being able to handle arabic.
Code for connecting to the database:
String url = "jdbc:mysql://127.0.0.1:3306/mydatabase";
String user = "root";
String passwd = ".........";
String unicode= "?useUnicode=yes&characterEncoding=UTF-8";
setConnection((Connection) DriverManager.getConnection(url+unicode, user, passwd));
Code for inserting the value:
query3 = "INSERT INTO keyword (idkeyword, keyword) VALUES ("+keyWord.getId()+",'عماد')";
Statement state7 = (Statement) connection.createStatement();
state7.executeUpdate(query3);
The exception that I'm receiving:
java.sql.SQLException: Incorrect string value: '\xD8\xB9\xD9\x85\xD8\xA7...' for column 'keyword' at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2482)
at com.mysql.jdbc.StatementImpl.executeUpdateInternal(StatementImpl.java:1552)
at com.mysql.jdbc.StatementImpl.executeLargeUpdate(StatementImpl.java:2607)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1480)
at controller.DataBaseAccess.saveProject(DataBaseAccess.java:285)
All help is greatly appreciated!
EDIT: The answers in the "“Incorrect string value” when trying to insert UTF-8 into MySQL via JDBC?" are all irrelevant to this case, because they revolve around using utf8mb4, which is not needed for Arabic characters (they are stored over 2 Bytes, not 4 bytes)