how to insert and get japanese characters.
Posted by: zjf_web
Date: May 25, 2005 04:43AM

how to insert and get japanese characters.
I use mysql 4.1.11-win, connector-java 3.1.7. Os: Win2000-Japan
From command line:
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 D:\MySQL\MySQL Server 4.1\share\charsets/.
And insert into DB from command line:
mysql>insert into dbname (id, name) values(1, '日本語');
And get through command line:
mysql>select * from dbname where id = 1;
id name
1 '日本語’
That's OK.

But When I do it from java(not jsp), it does not work. Here is parts of the source:
url="jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=utf-8";
......
String s = rs.getString(2);
SortedMap sm = Charset.availableCharsets();
ArrayList al = new ArrayList(sm.values());
String[] charsets = new String [al.size()];
for(int i = 0; i < al.size(); i++) {
charsets = al.get(i).toString();
}
for(int i = 0; i < al.size(); i++) {
String s1 = charsets;
System.out.println(new String(s.getBytes("utf-8"),s1));
}

This time it does not work. Though I tried all available charsets.
Anyone can tell me where is wrong?

Options: ReplyQuote


Subject
Written By
Posted
how to insert and get japanese characters.
May 25, 2005 04:43AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.