JDBCを使ってPostgreSQLなどにデータを登録しようとしたときに、
java.sql.SQLException: ERROR: character 0xe3809c of encoding "UNICODE" has no equivalent in "EUC_JP"
のようなエラーが表示されたことはないでしょうか?
チルダやハイフンなどがUNICODEとEUCの間でうまく変換されないのが原因のようです。
自分は以下の関数を使ってあらかじめUNICODEをMS932に変換して登録してます。
public static String encodeUNICODESQL(String str){ StringBuffer ret = new StringBuffer(); char c = 0x0000; for(int i=0; i < str.length(); i++){ c = str.charAt(i); switch(c){ case 0x301c: //チルダ c = 0xff5e; break; case 0x2212: //ハイフン case 0x2014: c = 0xff0d; break; case 0x2016: //二重の縦棒 c = 0x2225; break; case 0x00a3: //ポンド c = 0xffe1; break; case 0x00a2: //セント c = 0xffe0; break; } ret.append(c); } return ret.toString(); }
|