Arabic characters issues with MySQL database using Java

  • 0
  • Pump00:00

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 screenshots from Mysql Workbench:

and

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: 'xD8xB9xD9x85xD8xA7...' 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!

Default Asked on December 28, 2019 in Programming.
Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.