How can I insert arabic word to mysql database using java

Solution 1:

add this variable after db variable declaration:

String unicode= "?useUnicode=yes&characterEncoding=UTF-8";

and then modify your line:

con = DriverManager.getConnection(url+db,"root","");

to

con = DriverManager.getConnection(url+db+unicode,"root","");

Solution 2:

i faced the same problem but with Chinese data, and it is not only the UTF8 in the db connection is the solution you should also do this:

Ensure that your MySQL configuration encoding is defined correctly. Add these lines to either my.cnf "in the case if using linux" or my.ini "case you using windows"

[client] 
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
default-character-set=utf8
character-set-server=utf8