mysql:6722
From: (sumino) <<sumino@xxxxxxxxxx>>
Date: Tue, 17 Dec 2002 18:32:57 +0900
Subject: [mysql 06722] シフト JIS の文字化け
Win2000上で Java + MySQLのアプリケーションを作成しているのですが、
JDBC Type4 ドライバを使用してINSERTしたときに文字化けしてしまいます。
解決方法をご存知の方は教えてください。
「濱﨑」→「濱?」
「ⅰⅱⅲⅳⅴ」→「?????」となってしまいます。
使用したJDBCドライバ
gweMysqlJDBC_extra4
gweMysqlJDBC_extra3 gwe.sql.gweMysqlDriver
mysql-connector-java-2.0.14
mysql-connector-java-3.0.2-beta org.gjt.mm.mysql.Driver
sunのJDBC Type1 ドライバ sun.jdbc.odbc.JdbcOdbcDriver だと、うまくいきます。
JDBCドライバを使用せずに、コマンドから直接入力した場合も文字化けすることな
く、INSERTできます。
SELECTはうまくいきます。
ただ、「表」は文字化けしません。(過去に何度も話題になった「\」問題ではない
と思います。)
使用環境
windows 2000 pro sp3
mysql 3.23.51-nt
ローカルホストで使用しています。
j2sdk1.4.0_01
以下サンプルソース
1 import java.sql.*;
2
3 public class JDBCBatch{
4 public static void main(String[] args) {
5 Connection con = null;
6 Statement stmt = null;
7 String dburl =
"jdbc:mysql://localhost:3306/TestDB?useUnicode=true&characterEncoding=SJIS";
8
9 try {
10 // ドライバクラスをロード
11 // Class.forName("com.mysql.jdbc.Driver");
12 // Class.forName("gwe.sql.gweMysqlDriver");
13 Class.forName("org.gjt.mm.mysql.Driver");
14 // Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
15
16 // データベースへ接続
17 // con = DriverManager.getConnection("jdbc:odbc:TestDB", "", "");
18 con = DriverManager.getConnection(dburl,"root","masterkey");
19 // ステートメントオブジェクトを生成
20 stmt = con.createStatement();
21
22 /**処理1**/
23 stmt.addBatch("INSERT INTO Test (No,名前) VALUES('00004','ⅰⅱⅲⅳ
﨑')");
24
25 // バッチを実行します
26 stmt.executeBatch();
27
28 } catch (Exception e) {
29 e.printStackTrace();
30 } finally {
31 // データベースへの接続をクローズします
32 try {
33 if (stmt!=null) {
34 stmt.close();
35 }
36 if (con!=null) {
37 con.close();
38 }
39 } catch (SQLException e) {
40 e.printStackTrace();
41 }
42 }
43 }
44 }
------------------------------------------------------------
Name : Sumino Hiroshi
E-Mail : sumino@xxxxxxxxxx
-> 6722 2002-12-17 18:32 [<sumino@xxxxxxxxxx> ] シフト JIS の文字化け 6723 2002-12-17 22:56 ┣["城" <sora_iro@xxxxx] 6724 2002-12-17 23:16 ┗["TAKAHASHI, Tomohiro] 6725 2002-12-18 11:21 ┗[<sumino@xxxxxxxxxx> ]