Storing the chinese characters exactly in to mysql db .....Its urgent 4 me

hi

Thanx alot for every one.......

Here iam struggleling from last few weeks with this problem

That goes like this

How to insert a chinese character exctly in to the mysql data base(Iam using mysql-5.0)

Here i did some thing......please can you correct it if anything goes wrong..

Some where in the doc's i have searched in the net they are specified that change the default char set of client and server in my.ini

According to them here iam changed to utf8 in both places (client and server)

This file avilable in mysql root directory...

then iam

created database with chatset utf8

created a table with chatset utf8 and

specifing column with charset utf8 and collation utf8_general_ci

then

When i submitting the form the data which iam passing is converted to NCR (Like &amp#220027). formated string..this string iam getting in action class.here iam exactly strucked what should i with this string to connver to chinese character...Please give me what sort of steps sholud i follow here up to DB level ..

I kown that iam doing some thing wrong with my database configuration. please give me some explanation(if possible Example) how can i setup my database to set these chinese characters...

here iam specifying my db settings:

mysql> SHOW VARIABLES LIKE 'char%';

+--+-

| Variable_name| Value

+--+-

character_set_client| utf8

|

| character_set_connection | utf8

|

| character_set_database| utf8

|

| character_set_results| utf8

|

| character_set_server| utf8

|

| character_set_system| utf8

|

| character_sets_dir| C:\Program Files\MySQL\MySQL Server 5.0\share\chars

ets\ |

+--+-

--+

mysql> SHOW VARIABLES LIKE 'col%';

+-+--+

| Variable_name| Value|

+-+--+

| collation_connection | utf8_general_ci |

| collation_database| utf8_general_ci |

| collation_server| utf8_general_ci |

+-+--+

Please let me know if iam doing any thing wrong....

iam using jdbc to connect to the db..Here is my simple java code...

public class StroreChinese2DBUsingJdbc

{

public static void main(String args[]){

try {

Class.forName("com.mysql.jdbc.Driver");

String connectionUrl = "jdbc:mysql://localhost:3306/test?user=root&password=admin&databaseName=test&integratedSecurity=true&useUnicode=true&characterEncoding=utf8";

Connection con = null;

String str="件";

con = DriverManager.getConnection(connectionUrl);

str=StoreChineseChar2DBServlet.NCR2UnicodeString(str);

PreparedStatement ps1 = con.prepareStatement("insert into big5 values(?)");

ps1.setString(1, str);

int noofRows = ps1.executeUpdate();

System.out.println("No of rows effected::::"+noofRows);

PreparedStatement ps2 = con.prepareStatement("select * from big5");

ResultSet rs2=ps2.executeQuery();

while(rs2.next()){

System.out.println("effected data::::"+rs2.getString(1));

}

rs2.close();

ps1.close();

ps2.close();

con.close();

}catch (SQLException e) {

e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.

} /*catch (UnsupportedEncodingException e) {

e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.

} */catch (ClassNotFoundException e) {

e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.

}

}

public static String NCR2UnicodeString(String str)

{

StringBuffer ostr = new StringBuffer();

int i1=0;

int i2=0;

while(i2<str.length())

{

i1 = str.indexOf("&#",i2);

if (i1 == -1 ) {

ostr.append(str.substring(i2, str.length()));

break ;

}

ostr.append(str.substring(i2, i1));

i2 = str.indexOf(";", i1);

if (i2 == -1 ) {

ostr.append(str.substring(i1, str.length()));

break ;

}

String tok = str.substring(i1+2, i2);

try {

int radix = 10 ;

if (tok.trim().charAt(0) == 'x') {

radix = 16 ;

tok = tok.substring(1,tok.length());

}

ostr.append((char) Integer.parseInt(tok, radix));

} catch (NumberFormatException exp) {

ostr.append('?') ;

}

i2++ ;

}

return new String(ostr) ;

}

}

With this code it is stroring some junk value in side the db instead of chinese characters..

Iam very much thank full to every one ..iam really suffering with this from last few weeks...Please letme know is there any thing wrong in this programming ..

If the explanation in not proper please let know iam ready to explain.......again and again this is some what ungent for me...

Thanking you

Srikanth>

[5012 byte] By [srikanth_bsba] at [2007-11-27 3:11:17]
# 1
Have you tried to run the program without the following line of code:str=StoreChineseChar2DBServlet.NCR2UnicodeString(str);V.V.
viravana at 2007-7-12 8:13:44 > top of Java-index,Desktop,I18N...
# 2
Hi viravan Thanx alot for you reply...Yeah i tried the program with out that line what you are specified Here it it stroing the NCR string (&amp#220027)...Please can you telll me where is the problem...RegardsSrikanth
srikanth_bsba at 2007-7-12 8:13:44 > top of Java-index,Desktop,I18N...
# 3

Hard to say where the problem lies because the unicode value for str should be "\u20214" or 0x20214. I don't what what &amp#220027 is.

Although I see str=ji鄋 when I view the post, I suspect that the actual code you use is in a HTML format of "& # 20214;", you can try this:

String str="\u20214";

and delete the codes under NCR2UnicodeString as well as the code that calls NCR2UnicodeString.

Good Luck!

:)

VV

viravana at 2007-7-12 8:13:44 > top of Java-index,Desktop,I18N...