com.mysql.cj

## Class CharsetMapping

- java.lang.Object
- - com.mysql.cj.CharsetMapping

    public class CharsetMapping
    extends Object

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

Fields
`private static Map<String,MysqlCharset>` `CHARSET_NAME_TO_CHARSET`
`private static Map<String,Integer>` `CHARSET_NAME_TO_COLLATION_INDEX`
`private static Map<Integer,MysqlCharset>` `COLLATION_INDEX_TO_CHARSET`
`private static String[]` `COLLATION_INDEX_TO_COLLATION_NAME`
`private static Map<String,Integer>` `COLLATION_NAME_TO_COLLATION_INDEX`
`private static 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 Map<String,List<MysqlCharset>>` `JAVA_ENCODING_UC_TO_MYSQL_CHARSET`
`static int` `MAP_SIZE`
`private static Set<String>` `MULTIBYTE_ENCODINGS`
`static String` `MYSQL_CHARSET_NAME_armscii8`
`static String` `MYSQL_CHARSET_NAME_ascii`
`static String` `MYSQL_CHARSET_NAME_big5`
`static String` `MYSQL_CHARSET_NAME_binary`
`static String` `MYSQL_CHARSET_NAME_cp1250`
`static String` `MYSQL_CHARSET_NAME_cp1251`
`static String` `MYSQL_CHARSET_NAME_cp1256`
`static String` `MYSQL_CHARSET_NAME_cp1257`
`static String` `MYSQL_CHARSET_NAME_cp850`
`static String` `MYSQL_CHARSET_NAME_cp852`
`static String` `MYSQL_CHARSET_NAME_cp866`
`static String` `MYSQL_CHARSET_NAME_cp932`
`static String` `MYSQL_CHARSET_NAME_dec8`
`static String` `MYSQL_CHARSET_NAME_eucjpms`
`static String` `MYSQL_CHARSET_NAME_euckr`
`static String` `MYSQL_CHARSET_NAME_gb18030`
`static String` `MYSQL_CHARSET_NAME_gb2312`
`static String` `MYSQL_CHARSET_NAME_gbk`
`static String` `MYSQL_CHARSET_NAME_geostd8`
`static String` `MYSQL_CHARSET_NAME_greek`
`static String` `MYSQL_CHARSET_NAME_hebrew`
`static String` `MYSQL_CHARSET_NAME_hp8`
`static String` `MYSQL_CHARSET_NAME_keybcs2`
`static String` `MYSQL_CHARSET_NAME_koi8r`
`static String` `MYSQL_CHARSET_NAME_koi8u`
`static String` `MYSQL_CHARSET_NAME_latin1`
`static String` `MYSQL_CHARSET_NAME_latin2`
`static String` `MYSQL_CHARSET_NAME_latin5`
`static String` `MYSQL_CHARSET_NAME_latin7`
`static String` `MYSQL_CHARSET_NAME_macce`
`static String` `MYSQL_CHARSET_NAME_macroman`
`static String` `MYSQL_CHARSET_NAME_sjis`
`static String` `MYSQL_CHARSET_NAME_swe7`
`static String` `MYSQL_CHARSET_NAME_tis620`
`static String` `MYSQL_CHARSET_NAME_ucs2`
`static String` `MYSQL_CHARSET_NAME_ujis`
`static String` `MYSQL_CHARSET_NAME_utf16`
`static String` `MYSQL_CHARSET_NAME_utf16le`
`static String` `MYSQL_CHARSET_NAME_utf32`
`static String` `MYSQL_CHARSET_NAME_utf8`
`static String` `MYSQL_CHARSET_NAME_utf8mb3`
`static String` `MYSQL_CHARSET_NAME_utf8mb4`
`static int` `MYSQL_COLLATION_INDEX_binary`
`static int` `MYSQL_COLLATION_INDEX_utf8mb4_0900_ai_ci`
`static int` `MYSQL_COLLATION_INDEX_utf8mb4_general_ci`

### Constructor Summary

Constructors
`CharsetMapping()`

### Method Summary

All Methods Static Methods Concrete Methods
`protected static Integer` `getStaticCollationIndexForCollationName(String collationName)`
`protected static int` `getStaticCollationIndexForJavaEncoding(String javaEncoding, ServerVersion version)`
`protected static int` `getStaticCollationIndexForMysqlCharsetName(String charsetName)`
`static String` `getStaticCollationNameForCollationIndex(Integer collationIndex)`
`static String` `getStaticJavaEncodingForCollationIndex(Integer collationIndex)`
`protected static String` `getStaticJavaEncodingForCollationIndex(Integer collationIndex, String fallbackJavaEncoding)`
`protected static String` `getStaticJavaEncodingForMysqlCharset(String mysqlCharsetName)`
`protected static String` `getStaticJavaEncodingForMysqlCharset(String mysqlCharsetName, String fallbackJavaEncoding)` MySQL charset could map to several Java encodings.
`protected static int` `getStaticMblen(String charsetName)`
`protected static List<String>` `getStaticMysqlCharsetAliasesByName(String mysqlCharsetName)`
`protected static MysqlCharset` `getStaticMysqlCharsetByName(String mysqlCharsetName)`
`protected static String` `getStaticMysqlCharsetForJavaEncoding(String javaEncoding, ServerVersion version)`
`static String` `getStaticMysqlCharsetNameForCollationIndex(Integer collationIndex)`
`protected static boolean` `isStaticImpermissibleCollation(int collationIndex)`
`protected static boolean` `isStaticMultibyteCharset(String javaEncodingName)` Does the character set contain multi-byte encoded characters.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### MAP_SIZE

    public static final int MAP_SIZE

See Also:
  Constant Field Values

#### COLLATION_INDEX_TO_COLLATION_NAME

    private static final String[] COLLATION_INDEX_TO_COLLATION_NAME

#### COLLATION_INDEX_TO_CHARSET

    private static final Map<Integer,MysqlCharset> COLLATION_INDEX_TO_CHARSET

#### CHARSET_NAME_TO_CHARSET

    private static final Map<String,MysqlCharset> CHARSET_NAME_TO_CHARSET

#### CHARSET_NAME_TO_COLLATION_INDEX

    private static final Map<String,Integer> CHARSET_NAME_TO_COLLATION_INDEX

#### COLLATION_NAME_TO_COLLATION_INDEX

    private static final Map<String,Integer> COLLATION_NAME_TO_COLLATION_INDEX

#### JAVA_ENCODING_UC_TO_MYSQL_CHARSET

    private static final Map<String,List<MysqlCharset>> JAVA_ENCODING_UC_TO_MYSQL_CHARSET

#### MULTIBYTE_ENCODINGS

    private static final Set<String> MULTIBYTE_ENCODINGS

#### IMPERMISSIBLE_INDEXES

    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.

#### MYSQL_CHARSET_NAME_armscii8

    public static final String MYSQL_CHARSET_NAME_armscii8

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_ascii

    public static final String MYSQL_CHARSET_NAME_ascii

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_big5

    public static final String MYSQL_CHARSET_NAME_big5

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_binary

    public static final String MYSQL_CHARSET_NAME_binary

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_cp1250

    public static final String MYSQL_CHARSET_NAME_cp1250

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_cp1251

    public static final String MYSQL_CHARSET_NAME_cp1251

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_cp1256

    public static final String MYSQL_CHARSET_NAME_cp1256

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_cp1257

    public static final String MYSQL_CHARSET_NAME_cp1257

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_cp850

    public static final String MYSQL_CHARSET_NAME_cp850

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_cp852

    public static final String MYSQL_CHARSET_NAME_cp852

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_cp866

    public static final String MYSQL_CHARSET_NAME_cp866

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_cp932

    public static final String MYSQL_CHARSET_NAME_cp932

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_dec8

    public static final String MYSQL_CHARSET_NAME_dec8

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_eucjpms

    public static final String MYSQL_CHARSET_NAME_eucjpms

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_euckr

    public static final String MYSQL_CHARSET_NAME_euckr

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_gb18030

    public static final String MYSQL_CHARSET_NAME_gb18030

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_gb2312

    public static final String MYSQL_CHARSET_NAME_gb2312

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_gbk

    public static final String MYSQL_CHARSET_NAME_gbk

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_geostd8

    public static final String MYSQL_CHARSET_NAME_geostd8

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_greek

    public static final String MYSQL_CHARSET_NAME_greek

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_hebrew

    public static final String MYSQL_CHARSET_NAME_hebrew

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_hp8

    public static final String MYSQL_CHARSET_NAME_hp8

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_keybcs2

    public static final String MYSQL_CHARSET_NAME_keybcs2

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_koi8r

    public static final String MYSQL_CHARSET_NAME_koi8r

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_koi8u

    public static final String MYSQL_CHARSET_NAME_koi8u

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_latin1

    public static final String MYSQL_CHARSET_NAME_latin1

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_latin2

    public static final String MYSQL_CHARSET_NAME_latin2

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_latin5

    public static final String MYSQL_CHARSET_NAME_latin5

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_latin7

    public static final String MYSQL_CHARSET_NAME_latin7

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_macce

    public static final String MYSQL_CHARSET_NAME_macce

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_macroman

    public static final String MYSQL_CHARSET_NAME_macroman

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_sjis

    public static final String MYSQL_CHARSET_NAME_sjis

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_swe7

    public static final String MYSQL_CHARSET_NAME_swe7

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_tis620

    public static final String MYSQL_CHARSET_NAME_tis620

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_ucs2

    public static final String MYSQL_CHARSET_NAME_ucs2

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_ujis

    public static final String MYSQL_CHARSET_NAME_ujis

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_utf16

    public static final String MYSQL_CHARSET_NAME_utf16

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_utf16le

    public static final String MYSQL_CHARSET_NAME_utf16le

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_utf32

    public static final String MYSQL_CHARSET_NAME_utf32

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_utf8

    public static final String MYSQL_CHARSET_NAME_utf8

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_utf8mb3

    public static final String MYSQL_CHARSET_NAME_utf8mb3

See Also:
  Constant Field Values

#### MYSQL_CHARSET_NAME_utf8mb4

    public static final String MYSQL_CHARSET_NAME_utf8mb4

See Also:
  Constant Field Values

#### MYSQL_COLLATION_INDEX_utf8mb4_general_ci

    public static final int MYSQL_COLLATION_INDEX_utf8mb4_general_ci

See Also:
  Constant Field Values

#### MYSQL_COLLATION_INDEX_utf8mb4_0900_ai_ci

    public static final int MYSQL_COLLATION_INDEX_utf8mb4_0900_ai_ci

See Also:
  Constant Field Values

#### MYSQL_COLLATION_INDEX_binary

    public static final int MYSQL_COLLATION_INDEX_binary

See Also:
  Constant Field Values

### Constructor Detail

#### CharsetMapping

    public CharsetMapping()

### Method Detail

#### getStaticMysqlCharsetForJavaEncoding

    protected static String getStaticMysqlCharsetForJavaEncoding(String javaEncoding,
                                                                 ServerVersion version)

#### getStaticCollationIndexForJavaEncoding

    protected static int getStaticCollationIndexForJavaEncoding(String javaEncoding,
                                                                ServerVersion version)

#### getStaticCollationIndexForMysqlCharsetName

    protected static int getStaticCollationIndexForMysqlCharsetName(String charsetName)

#### getStaticMysqlCharsetNameForCollationIndex

    public static String getStaticMysqlCharsetNameForCollationIndex(Integer collationIndex)

#### getStaticCollationNameForCollationIndex

    public static String getStaticCollationNameForCollationIndex(Integer collationIndex)

#### getStaticCollationIndexForCollationName

    protected static Integer getStaticCollationIndexForCollationName(String collationName)

#### getStaticJavaEncodingForMysqlCharset

    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` - MySQL charset name
  `fallbackJavaEncoding` - fall-back java encoding name
Returns:
  java encoding name

#### getStaticMysqlCharsetByName

    protected static MysqlCharset getStaticMysqlCharsetByName(String mysqlCharsetName)

#### getStaticMysqlCharsetAliasesByName

    protected static List<String> getStaticMysqlCharsetAliasesByName(String mysqlCharsetName)

#### getStaticJavaEncodingForMysqlCharset

    protected static String getStaticJavaEncodingForMysqlCharset(String mysqlCharsetName)

#### getStaticJavaEncodingForCollationIndex

    protected static String getStaticJavaEncodingForCollationIndex(Integer collationIndex,
                                                                   String fallbackJavaEncoding)

#### getStaticJavaEncodingForCollationIndex

    public static String getStaticJavaEncodingForCollationIndex(Integer collationIndex)

#### isStaticMultibyteCharset

    protected static boolean isStaticMultibyteCharset(String javaEncodingName)

Does the character set contain multi-byte encoded characters.

Parameters:
  `javaEncodingName` - java encoding name
Returns:
  true if the character set contains multi-byte encoded characters.

#### getStaticMblen

    protected static int getStaticMblen(String charsetName)

#### isStaticImpermissibleCollation

    protected static boolean isStaticImpermissibleCollation(int collationIndex)

Copyright © 2016, 2026, Oracle and/or its affiliates.