[前][次][番号順一覧][スレッド一覧]

mysql:7703

From: "eMantra Information" <"eMantra Information" <info@xxxxxxxxxx>>
Date: Wed, 14 May 2003 12:17:47 +0530
Subject: [mysql 07703] Re: why certain Japanese characters are getting displayed as wrong characters?

Hi guys,

I looked into the various aspects of the problem and solutions.

1. what has been said about the '\' character in the responses is right.
This is causing problem.

So I tried/thought solutions suggested...

a. use utf-8 instead of shift_jis
not practical as there is lot of shift_jis data by now in database

b. insert one more escape character before (or after) the 0x5c
which will solve the problem with involves good amt of work in my code

c. modify my.ini file to set 'default-character-set=sjis'
My app will be hosted with commercial hosting service provider. hense i am
not in control of it.
and may not be able to do this.


2. This raises a question.
Fine we can solve the problem for '\'
Are there any other characters which MySQL would not like?
Do I have to take care of any other character(s)?

3. I tried another solution. It seemed to work.
I do not know how and why.
here is what I did.

Instead of doing following

	request.setCharacterEncoding ("Shift_JIS");
	String name = request.getParameter("name");
	String newName = insertSingleQuote(name);	// insert single quote around the
string
	newName = replaceChar(newName, '\\', "\\\\");
	....
	String sql = "insert into test_table values (" + newName + ")";
	statement.executeUpdate(sql);

I DID FOLLOWING

	//request.setCharacterEncoding ("Shift_JIS");	// do not need this now.
	String name = request.getParameter("name");
	byte [] arrShift_JIS = name.getBytes("Shift_JIS");	// instead of using
utf-8 string into the sql query directly use the byte array in shift_jis
form
	PreparedStatement preparedStatement = connection.prepareStatement("insert
into test_table values (?)");
	preparedStatement.setBytes(1, arrShift_JIS);
	preparedStatement.executeUpdate();


Now this seems to solve the problem (possibly the JDBC driver/implementation
will do appropriate escaping....)
So my question to u guys is ...
a. why does this work?
b. is this a right solution? and
c. will it take care of all the problematic characters?

regards,
Haresh Gujarathi


-----Original Message-----
From: Shimono Osamu [mailto:shimono@xxxxxxxxxx]
Sent: Monday, May 12, 2003 4:15 PM
To: ml@xxxxxxxxxx
Subject: [mysql 07687] Re: why certain Japanese characters are getting
displayed as wrong characters?


> Can somebody throw light on this?
>
> Since the Jap characters may not come up in this forum html pages...
> I have put GIF and txt files on following link. These pages will show u
the
> intended Jap characters and the actual characters coming up on html page
> Please visit following links to view the pages, and do provide some
> information regarding this behavior
> http://www.emantratech.com/jap_text/japanese-text-problem.htm
> http://www.emantratech.com/jap_text/event3731.gif
>
> Haresh Gujarathi

Hi, Haresh.

x8868(UTF-16) = x955C(SJIS)
x73FE(UTF-16) = x8CBB(SJIS)

Some of Shift-Jis character contains code '5C' in its second byte.
You know, code '5C' is the escape-character(\).
When MySQL reads your SQL syntax, escape-character(5C) and next one
character
will be ignored(removed). Then your SQL syntax gets corrupted.
So, You need to insert '5C' just after the '5C' in your syntax.
Double escape-character(\\) means single character'\'.

Or, modify my.ini file to set 'default-character-set=sjis',
and make it sure 'mysql>status' command describes
'default-character-set=sjis'.

regards

Osamu Shimono


[前][次][番号順一覧][スレッド一覧]

      7684 2003-05-12 17:36 ["eMantra Information] why certain Japanese characters are getting displayed as wrong characters?
      7686 2003-05-12 19:27 ┣[Masaki Ikeda <masaki]                                       
      7694 2003-05-13 16:02 ┃┗["eMantra Information]                                     
      7697 2003-05-13 16:27 ┃ ┗[Joel Rees <joel@xxxx]                                   
      7687 2003-05-12 19:45 ┗["Shimono Osamu" <shi]                                       
->    7703 2003-05-14 15:47  ┗["eMantra Information]                                     
      7706 2003-05-14 17:27   ┣["Shimono Osamu" <shi]                                   
      7708 2003-05-14 18:14   ┗[Joel Rees <joel@xxxx]