Top Description Fields Constructors Methods
com.mysql.cj

public Class CharsetMapping

Additional top-level classes in compilation unit: MysqlCharset, Collation.

extends Object
Class Inheritance
Known Direct Subclasses
com.mysql.cj.NativeCharsetSettings
Imports
java.nio.charset.Charset, java.util.ArrayList, .Arrays, .Collections, .HashMap, .HashSet, .List, .Locale, .Map, .Set, .TreeMap

Mapping between MySQL charset names and Java charset names. I've investigated placing these in a .properties file, but unfortunately under most appservers this complicates configuration because the security policy needs to be changed by the user to allow the driver to read them :(

Field Summary

Modifier and TypeField and Description
private static final Map<String, MysqlCharset>
private static final Map<String, Integer>
private static final Map<Integer, MysqlCharset>
private static final String[]
private static final Map<String, Integer>
private static final Set<Integer>
IMPERMISSIBLE_INDEXES

Indexes of collations using ucs2, utf16, utf16le or utf32 character sets and that cannot be set to character_set_client system variable.

private static final Map<String, List<MysqlCharset>>
public static final int
private static final Set<String>
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected static Integer
protected static int
protected static int
public static String
protected static String
getStaticJavaEncodingForCollationIndex(Integer collationIndex, String fallbackJavaEncoding)

public static String
protected static String

Returns:

java encoding name
getStaticJavaEncodingForMysqlCharset
(String
MySQL charset name
mysqlCharsetName
,
String
fall-back java encoding name
fallbackJavaEncoding
)

MySQL charset could map to several Java encodings.

protected static String
protected static int
getStaticMblen(String charsetName)

protected static List<String>
protected static MysqlCharset
protected static String
public static String
protected static boolean
isStaticImpermissibleCollation(int collationIndex)

protected static boolean

Returns:

true if the character set contains multi-byte encoded characters.
isStaticMultibyteCharset
(String
java encoding name
javaEncodingName
)

Does the character set contain multi-byte encoded characters.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CHARSET_NAME_TO_CHARSETback to summary
private static final Map<String, MysqlCharset> CHARSET_NAME_TO_CHARSET
CHARSET_NAME_TO_COLLATION_INDEXback to summary
private static final Map<String, Integer> CHARSET_NAME_TO_COLLATION_INDEX
COLLATION_INDEX_TO_CHARSETback to summary
private static final Map<Integer, MysqlCharset> COLLATION_INDEX_TO_CHARSET
COLLATION_INDEX_TO_COLLATION_NAMEback to summary
private static final String[] COLLATION_INDEX_TO_COLLATION_NAME
COLLATION_NAME_TO_COLLATION_INDEXback to summary
private static final Map<String, Integer> COLLATION_NAME_TO_COLLATION_INDEX
IMPERMISSIBLE_INDEXESback to summary
private static final Set<Integer> IMPERMISSIBLE_INDEXES

Indexes of collations using ucs2, utf16, utf16le or utf32 character sets and that cannot be set to character_set_client system variable.

JAVA_ENCODING_UC_TO_MYSQL_CHARSETback to summary
private static final Map<String, List<MysqlCharset>> JAVA_ENCODING_UC_TO_MYSQL_CHARSET
MAP_SIZEback to summary
public static final int MAP_SIZE
MULTIBYTE_ENCODINGSback to summary
private static final Set<String> MULTIBYTE_ENCODINGS
MYSQL_CHARSET_NAME_armscii8back to summary
public static final String MYSQL_CHARSET_NAME_armscii8
MYSQL_CHARSET_NAME_asciiback to summary
public static final String MYSQL_CHARSET_NAME_ascii
MYSQL_CHARSET_NAME_big5back to summary
public static final String MYSQL_CHARSET_NAME_big5
MYSQL_CHARSET_NAME_binaryback to summary
public static final String MYSQL_CHARSET_NAME_binary
MYSQL_CHARSET_NAME_cp1250back to summary
public static final String MYSQL_CHARSET_NAME_cp1250
MYSQL_CHARSET_NAME_cp1251back to summary
public static final String MYSQL_CHARSET_NAME_cp1251
MYSQL_CHARSET_NAME_cp1256back to summary
public static final String MYSQL_CHARSET_NAME_cp1256
MYSQL_CHARSET_NAME_cp1257back to summary
public static final String MYSQL_CHARSET_NAME_cp1257
MYSQL_CHARSET_NAME_cp850back to summary
public static final String MYSQL_CHARSET_NAME_cp850
MYSQL_CHARSET_NAME_cp852back to summary
public static final String MYSQL_CHARSET_NAME_cp852
MYSQL_CHARSET_NAME_cp866back to summary
public static final String MYSQL_CHARSET_NAME_cp866
MYSQL_CHARSET_NAME_cp932back to summary
public static final String MYSQL_CHARSET_NAME_cp932
MYSQL_CHARSET_NAME_dec8back to summary
public static final String MYSQL_CHARSET_NAME_dec8
MYSQL_CHARSET_NAME_eucjpmsback to summary
public static final String MYSQL_CHARSET_NAME_eucjpms
MYSQL_CHARSET_NAME_euckrback to summary
public static final String MYSQL_CHARSET_NAME_euckr
MYSQL_CHARSET_NAME_gb18030back to summary
public static final String MYSQL_CHARSET_NAME_gb18030
MYSQL_CHARSET_NAME_gb2312back to summary
public static final String MYSQL_CHARSET_NAME_gb2312
MYSQL_CHARSET_NAME_gbkback to summary
public static final String MYSQL_CHARSET_NAME_gbk
MYSQL_CHARSET_NAME_geostd8back to summary
public static final String MYSQL_CHARSET_NAME_geostd8
MYSQL_CHARSET_NAME_greekback to summary
public static final String MYSQL_CHARSET_NAME_greek
MYSQL_CHARSET_NAME_hebrewback to summary
public static final String MYSQL_CHARSET_NAME_hebrew
MYSQL_CHARSET_NAME_hp8back to summary
public static final String MYSQL_CHARSET_NAME_hp8
MYSQL_CHARSET_NAME_keybcs2back to summary
public static final String MYSQL_CHARSET_NAME_keybcs2
MYSQL_CHARSET_NAME_koi8rback to summary
public static final String MYSQL_CHARSET_NAME_koi8r
MYSQL_CHARSET_NAME_koi8uback to summary
public static final String MYSQL_CHARSET_NAME_koi8u
MYSQL_CHARSET_NAME_latin1back to summary
public static final String MYSQL_CHARSET_NAME_latin1
MYSQL_CHARSET_NAME_latin2back to summary
public static final String MYSQL_CHARSET_NAME_latin2
MYSQL_CHARSET_NAME_latin5back to summary
public static final String MYSQL_CHARSET_NAME_latin5
MYSQL_CHARSET_NAME_latin7back to summary
public static final String MYSQL_CHARSET_NAME_latin7
MYSQL_CHARSET_NAME_macceback to summary
public static final String MYSQL_CHARSET_NAME_macce
MYSQL_CHARSET_NAME_macromanback to summary
public static final String MYSQL_CHARSET_NAME_macroman
MYSQL_CHARSET_NAME_sjisback to summary
public static final String MYSQL_CHARSET_NAME_sjis
MYSQL_CHARSET_NAME_swe7back to summary
public static final String MYSQL_CHARSET_NAME_swe7
MYSQL_CHARSET_NAME_tis620back to summary
public static final String MYSQL_CHARSET_NAME_tis620
MYSQL_CHARSET_NAME_ucs2back to summary
public static final String MYSQL_CHARSET_NAME_ucs2
MYSQL_CHARSET_NAME_ujisback to summary
public static final String MYSQL_CHARSET_NAME_ujis
MYSQL_CHARSET_NAME_utf16back to summary
public static final String MYSQL_CHARSET_NAME_utf16
MYSQL_CHARSET_NAME_utf16leback to summary
public static final String MYSQL_CHARSET_NAME_utf16le
MYSQL_CHARSET_NAME_utf32back to summary
public static final String MYSQL_CHARSET_NAME_utf32
MYSQL_CHARSET_NAME_utf8back to summary
public static final String MYSQL_CHARSET_NAME_utf8
MYSQL_CHARSET_NAME_utf8mb3back to summary
public static final String MYSQL_CHARSET_NAME_utf8mb3
MYSQL_CHARSET_NAME_utf8mb4back to summary
public static final String MYSQL_CHARSET_NAME_utf8mb4
MYSQL_COLLATION_INDEX_binaryback to summary
public static final int MYSQL_COLLATION_INDEX_binary
MYSQL_COLLATION_INDEX_utf8mb4_0900_ai_ciback to summary
public static final int MYSQL_COLLATION_INDEX_utf8mb4_0900_ai_ci
MYSQL_COLLATION_INDEX_utf8mb4_general_ciback to summary
public static final int MYSQL_COLLATION_INDEX_utf8mb4_general_ci

Constructor Detail

CharsetMappingback to summary
public CharsetMapping()

Method Detail

getStaticCollationIndexForCollationNameback to summary
protected static Integer getStaticCollationIndexForCollationName(String collationName)
getStaticCollationIndexForJavaEncodingback to summary
protected static int getStaticCollationIndexForJavaEncoding(String javaEncoding, ServerVersion version)
getStaticCollationIndexForMysqlCharsetNameback to summary
protected static int getStaticCollationIndexForMysqlCharsetName(String charsetName)
getStaticCollationNameForCollationIndexback to summary
public static String getStaticCollationNameForCollationIndex(Integer collationIndex)
getStaticJavaEncodingForCollationIndexback to summary
protected static String getStaticJavaEncodingForCollationIndex(Integer collationIndex, String fallbackJavaEncoding)
getStaticJavaEncodingForCollationIndexback to summary
public static String getStaticJavaEncodingForCollationIndex(Integer collationIndex)
getStaticJavaEncodingForMysqlCharsetback to summary
protected static String getStaticJavaEncodingForMysqlCharset(String mysqlCharsetName, String fallbackJavaEncoding)

MySQL charset could map to several Java encodings. So here we choose the one according to next rules:

  • if there is no static mapping for this charset then return javaEncoding value as is because this could be a custom charset for example
  • if static mapping exists and javaEncoding equals to one of Java encoding canonical names or aliases available for this mapping then javaEncoding value as is; this is required when result should match to connection encoding, for example if connection encoding is Cp943 we must avoid getting SHIFT_JIS for sjis mysql charset
  • if static mapping exists and javaEncoding doesn't match any Java encoding canonical names or aliases available for this mapping then return default Java encoding (the first in mapping list)
Parameters
mysqlCharsetName:String

MySQL charset name

fallbackJavaEncoding:String

fall-back java encoding name

Returns:String

java encoding name

getStaticJavaEncodingForMysqlCharsetback to summary
protected static String getStaticJavaEncodingForMysqlCharset(String mysqlCharsetName)
getStaticMblenback to summary
protected static int getStaticMblen(String charsetName)
getStaticMysqlCharsetAliasesByNameback to summary
protected static List<String> getStaticMysqlCharsetAliasesByName(String mysqlCharsetName)
getStaticMysqlCharsetByNameback to summary
protected static MysqlCharset getStaticMysqlCharsetByName(String mysqlCharsetName)
getStaticMysqlCharsetForJavaEncodingback to summary
protected static String getStaticMysqlCharsetForJavaEncoding(String javaEncoding, ServerVersion version)
getStaticMysqlCharsetNameForCollationIndexback to summary
public static String getStaticMysqlCharsetNameForCollationIndex(Integer collationIndex)
isStaticImpermissibleCollationback to summary
protected static boolean isStaticImpermissibleCollation(int collationIndex)
isStaticMultibyteCharsetback to summary
protected static boolean isStaticMultibyteCharset(String javaEncodingName)

Does the character set contain multi-byte encoded characters.

Parameters
javaEncodingName:String

java encoding name

Returns:boolean

true if the character set contains multi-byte encoded characters.