1

While creating database for my website I used below syntax.

CREATE DATABASE myDatabase DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

Now while my client is entering arabic characters, he see some weird output. I am using JSF 2.0 for web pages.

What changes do I need to make so that I can enter Arabic or any characters in my site and it get stored in DB.

Edit 1

While I am printing the data, I am seeing output as شسÙ?بشسÙ? بشسÙ?ب شسÙ?ب

Note:

I am using web application using JSF 2.0

  • 1
    First, is the data saved in the database correctly? Where are you seeing the output from? – babooney Nov 19 '12 at 08:53
  • @babooney : while reading the data, and print it using System.out.println I see output as `شسÙ?بشسÙ? بشسÙ?ب شسÙ?ب` –  Nov 19 '12 at 08:56
  • 1
    possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Pekka Nov 19 '12 at 08:57
  • @SreenathSoman : how to check whether its UTF-8 or ANSI? –  Nov 19 '12 at 09:06
  • sorry its not ANSI, it is ISO-8859-1.. anyway which server are you using ? – Sreenath S Nov 19 '12 at 09:12
  • @SreenathSoman : I am using hosting my site on from hosting site. I have Tomcat there... –  Nov 19 '12 at 09:15
  • check this: http://wiki.apache.org/tomcat/FAQ/CharacterEncoding#Q1 – Sreenath S Nov 19 '12 at 09:20
  • this would help you i think, http://stackoverflow.com/a/1125802/1600692 – Sreenath S Nov 19 '12 at 09:25
  • Someone else was having exactly the same problem today (your colleague or just a clone account of yourself?): http://stackoverflow.com/questions/13451061/why-arabic-letters-are-not-inserting-in-database – BalusC Nov 19 '12 at 11:59

3 Answers3

1

You should set UTF8 charset for the connection before the inserting/reading data -

SET NAMES utf8;
INSERT INTO table VALUES(...);

SELECT * FROM table;
Devart
  • 119,203
  • 23
  • 166
  • 186
  • I am using JSF 2.0. I did as you said, while I get exception as `java.sql.SQLException: Incorrect string value: '\xD9?\xD8\xB4\xD8\xB4...' for column 'fullName' at row 1` –  Nov 19 '12 at 09:05
1

Use N'' when you insert data values, This denotes that the subsequent string is in Unicode (the N actually stands for National language character set)

INSERT INTO table VALUES(N'ArabicField');
Alaa Alweish
  • 8,904
  • 16
  • 57
  • 84
0

I think you must use cp1256_general_ci instead of utf8_general_ci, and don't forget to set the collation of the database and all fields that may contain Arabic words to utf8_general_ci.