1 19 package com.mysql.jdbc; 20 21 import java.util.Collections ; 22 import java.util.HashMap ; 23 import java.util.Iterator ; 24 import java.util.Map ; 25 import java.util.Set ; 26 27 28 39 public class CharsetMapping { 40 42 45 public static final Map JAVA_TO_MYSQL_CHARSET_MAP; 46 47 50 public static final Map CHARSETMAP; 51 52 55 public static final Map MULTIBYTE_CHARSETS; 56 57 60 public static final String [] INDEX_TO_CHARSET; 61 62 static { 63 HashMap tempMap = new HashMap (); 64 65 tempMap.put("usa7", "US-ASCII"); 66 tempMap.put("big5", "Big5"); 67 tempMap.put("gbk", "GBK"); 68 tempMap.put("sjis", "SJIS"); 69 tempMap.put("gb2312", "EUC_CN"); 70 tempMap.put("ujis", "EUC_JP"); 71 tempMap.put("euc_kr", "EUC_KR"); 72 tempMap.put("latin1", "ISO8859_1"); 73 tempMap.put("latin1_de", "ISO8859_1"); 74 tempMap.put("german1", "ISO8859_1"); 75 tempMap.put("danish", "ISO8859_1"); 76 tempMap.put("latin2", "ISO8859_2"); 77 tempMap.put("czech", "ISO8859_2"); 78 tempMap.put("hungarian", "ISO8859_2"); 79 tempMap.put("croat", "ISO8859_2"); 80 tempMap.put("greek", "ISO8859_7"); 81 tempMap.put("hebrew", "ISO8859_8"); 82 tempMap.put("latin5", "ISO8859_9"); 83 tempMap.put("latvian", "ISO8859_13"); 84 tempMap.put("latvian1", "ISO8859_13"); 85 tempMap.put("estonia", "ISO8859_13"); 86 tempMap.put("dos", "Cp437"); 87 tempMap.put("pclatin2", "Cp852"); 88 tempMap.put("cp866", "Cp866"); 89 tempMap.put("koi8_ru", "KOI8_R"); 90 tempMap.put("tis620", "TIS620"); 91 tempMap.put("win1250", "Cp1250"); 92 tempMap.put("win1250ch", "Cp1250"); 93 tempMap.put("win1251", "Cp1251"); 94 tempMap.put("cp1251", "Cp1251"); 95 tempMap.put("win1251ukr", "Cp1251"); 96 tempMap.put("cp1257", "Cp1257"); 97 tempMap.put("macroman", "MacRoman"); 98 tempMap.put("macce", "MacCentralEurope"); 99 tempMap.put("utf8", "UTF-8"); 100 tempMap.put("ucs2", "UnicodeBig"); 101 102 CHARSETMAP = Collections.unmodifiableMap(tempMap); 103 104 HashMap javaToMysqlMap = new HashMap (); 105 106 Set keySet = CHARSETMAP.keySet(); 107 108 Iterator keys = keySet.iterator(); 109 110 while (keys.hasNext()) { 111 Object mysqlEncodingName = keys.next(); 112 Object javaEncodingName = CHARSETMAP.get(mysqlEncodingName); 113 114 if ("ISO8859_1".equals(javaEncodingName)) { 119 if ("latin1".equals(mysqlEncodingName)) { 120 javaToMysqlMap.put(javaEncodingName, mysqlEncodingName); 121 } 122 } else if ("ISO8859_2".equals(javaEncodingName)) { 123 if ("latin2".equals(mysqlEncodingName)) { 124 javaToMysqlMap.put(javaEncodingName, mysqlEncodingName); 125 } 126 } 127 else if ("ISO8859_13".equals(javaEncodingName)) { 128 if ("latin7".equals(mysqlEncodingName)) { 129 javaToMysqlMap.put(javaEncodingName, mysqlEncodingName); 130 } 131 } else { 132 javaToMysqlMap.put(javaEncodingName, mysqlEncodingName); 133 } 134 } 135 136 JAVA_TO_MYSQL_CHARSET_MAP = Collections.unmodifiableMap(javaToMysqlMap); 137 138 HashMap tempMapMulti = new HashMap (); 143 144 tempMapMulti.put("big5", "big5"); 145 tempMapMulti.put("euc_kr", "euc_kr"); 146 tempMapMulti.put("gb2312", "gb2312"); 147 tempMapMulti.put("gbk", "gbk"); 148 tempMapMulti.put("sjis", "sjis"); 149 tempMapMulti.put("ujis", "ujist"); 150 tempMapMulti.put("utf8", "utf8"); 151 tempMapMulti.put("ucs2", "UnicodeBig"); 152 153 MULTIBYTE_CHARSETS = Collections.unmodifiableMap(tempMapMulti); 154 155 INDEX_TO_CHARSET = new String [64]; 156 157 INDEX_TO_CHARSET[1] = (String ) CHARSETMAP.get("big5"); 158 INDEX_TO_CHARSET[2] = (String ) CHARSETMAP.get(" czech"); 159 INDEX_TO_CHARSET[3] = (String ) CHARSETMAP.get("dec8"); 160 INDEX_TO_CHARSET[4] = (String ) CHARSETMAP.get("dos"); 161 INDEX_TO_CHARSET[5] = (String ) CHARSETMAP.get("german1"); 162 INDEX_TO_CHARSET[6] = (String ) CHARSETMAP.get("hp8"); 163 INDEX_TO_CHARSET[7] = (String ) CHARSETMAP.get("koi8_ru"); 164 INDEX_TO_CHARSET[8] = (String ) CHARSETMAP.get("latin1"); 165 INDEX_TO_CHARSET[9] = (String ) CHARSETMAP.get("latin2"); 166 INDEX_TO_CHARSET[10] = (String ) CHARSETMAP.get("swe7"); 167 INDEX_TO_CHARSET[11] = (String ) CHARSETMAP.get("usa7"); 168 INDEX_TO_CHARSET[12] = (String ) CHARSETMAP.get("ujis"); 169 INDEX_TO_CHARSET[13] = (String ) CHARSETMAP.get("sjis"); 170 INDEX_TO_CHARSET[14] = (String ) CHARSETMAP.get("cp1251"); 171 INDEX_TO_CHARSET[15] = (String ) CHARSETMAP.get("danish"); 172 INDEX_TO_CHARSET[16] = (String ) CHARSETMAP.get("hebrew"); 173 INDEX_TO_CHARSET[18] = (String ) CHARSETMAP.get("tis620"); 174 INDEX_TO_CHARSET[19] = (String ) CHARSETMAP.get("euc_kr"); 175 INDEX_TO_CHARSET[20] = (String ) CHARSETMAP.get("estonia"); 176 INDEX_TO_CHARSET[21] = (String ) CHARSETMAP.get("hungarian"); 177 INDEX_TO_CHARSET[22] = (String ) CHARSETMAP.get("koi8_ukr"); 178 INDEX_TO_CHARSET[23] = (String ) CHARSETMAP.get("win1251ukr"); 179 INDEX_TO_CHARSET[24] = (String ) CHARSETMAP.get("gb2312"); 180 INDEX_TO_CHARSET[25] = (String ) CHARSETMAP.get("greek"); 181 INDEX_TO_CHARSET[26] = (String ) CHARSETMAP.get("win1250"); 182 INDEX_TO_CHARSET[27] = (String ) CHARSETMAP.get("croat"); 183 INDEX_TO_CHARSET[28] = (String ) CHARSETMAP.get("gbk"); 184 INDEX_TO_CHARSET[29] = (String ) CHARSETMAP.get("cp1257"); 185 INDEX_TO_CHARSET[30] = (String ) CHARSETMAP.get("latin5"); 186 INDEX_TO_CHARSET[31] = (String ) CHARSETMAP.get("latin1_de"); 187 INDEX_TO_CHARSET[32] = (String ) CHARSETMAP.get("armscii8"); 188 INDEX_TO_CHARSET[33] = (String ) CHARSETMAP.get("utf8"); 189 INDEX_TO_CHARSET[34] = (String ) CHARSETMAP.get("win1250ch"); 190 INDEX_TO_CHARSET[35] = (String ) CHARSETMAP.get("ucs2"); 191 INDEX_TO_CHARSET[36] = (String ) CHARSETMAP.get("cp866"); 192 INDEX_TO_CHARSET[37] = (String ) CHARSETMAP.get("keybcs2"); 193 INDEX_TO_CHARSET[38] = (String ) CHARSETMAP.get("macce"); 194 INDEX_TO_CHARSET[39] = (String ) CHARSETMAP.get("macroman"); 195 INDEX_TO_CHARSET[40] = (String ) CHARSETMAP.get("pclatin2"); 196 INDEX_TO_CHARSET[41] = (String ) CHARSETMAP.get("latvian"); 197 INDEX_TO_CHARSET[42] = (String ) CHARSETMAP.get("latvian1"); 198 INDEX_TO_CHARSET[43] = (String ) CHARSETMAP.get("maccebin"); 199 INDEX_TO_CHARSET[44] = (String ) CHARSETMAP.get("macceciai"); 200 INDEX_TO_CHARSET[45] = (String ) CHARSETMAP.get("maccecias"); 201 INDEX_TO_CHARSET[46] = (String ) CHARSETMAP.get("maccecsas"); 202 INDEX_TO_CHARSET[47] = (String ) CHARSETMAP.get("latin1bin"); 203 INDEX_TO_CHARSET[48] = (String ) CHARSETMAP.get("latin1cias"); 204 INDEX_TO_CHARSET[49] = (String ) CHARSETMAP.get("latin1csas"); 205 INDEX_TO_CHARSET[50] = (String ) CHARSETMAP.get("cp1251bin"); 206 INDEX_TO_CHARSET[51] = (String ) CHARSETMAP.get("cp1251cias"); 207 INDEX_TO_CHARSET[52] = (String ) CHARSETMAP.get("cp1251csas"); 208 INDEX_TO_CHARSET[53] = (String ) CHARSETMAP.get("macromanbin"); 209 INDEX_TO_CHARSET[54] = (String ) CHARSETMAP.get("macromancias"); 210 INDEX_TO_CHARSET[55] = (String ) CHARSETMAP.get("macromanciai"); 211 INDEX_TO_CHARSET[56] = (String ) CHARSETMAP.get("macromancsas"); 212 INDEX_TO_CHARSET[57] = (String ) CHARSETMAP.get("cp1256"); 213 INDEX_TO_CHARSET[63] = (String ) CHARSETMAP.get("binary"); 214 } 215 } 216 | Popular Tags |