Class CharsetMapping

java.lang.Object
com.mysql.jdbc.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 Details

    • MAP_SIZE

      public static final int MAP_SIZE
      See Also:
    • COLLATION_INDEX_TO_COLLATION_NAME

      public static final String[] COLLATION_INDEX_TO_COLLATION_NAME
    • COLLATION_INDEX_TO_CHARSET

      public static final MysqlCharset[] COLLATION_INDEX_TO_CHARSET
    • CHARSET_NAME_TO_CHARSET

      public static final Map<String, MysqlCharset> CHARSET_NAME_TO_CHARSET
    • CHARSET_NAME_TO_COLLATION_INDEX

      public static final Map<String,Integer> CHARSET_NAME_TO_COLLATION_INDEX
    • UTF8MB4_INDEXES

      public static final Set<Integer> UTF8MB4_INDEXES
    • NOT_USED

      public static final String NOT_USED
      See Also:
    • COLLATION_NOT_DEFINED

      public static final String COLLATION_NOT_DEFINED
      See Also:
    • MYSQL_COLLATION_INDEX_utf8

      public static final int MYSQL_COLLATION_INDEX_utf8
      See Also:
    • MYSQL_COLLATION_INDEX_binary

      public static final int MYSQL_COLLATION_INDEX_binary
      See Also:
  • Constructor Details

    • CharsetMapping

      public CharsetMapping()
  • Method Details

    • getMysqlCharsetForJavaEncoding

      public static final String getMysqlCharsetForJavaEncoding(String javaEncoding, Connection conn) throws SQLException
      Throws:
      SQLException
    • getCollationIndexForJavaEncoding

      public static int getCollationIndexForJavaEncoding(String javaEncoding, Connection conn) throws SQLException
      Throws:
      SQLException
    • getMysqlCharsetNameForCollationIndex

      public static String getMysqlCharsetNameForCollationIndex(Integer collationIndex)
    • getJavaEncodingForMysqlCharset

      public static String getJavaEncodingForMysqlCharset(String mysqlCharsetName, String javaEncoding)
      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 -
      javaEncoding -
    • getJavaEncodingForMysqlCharset

      public static String getJavaEncodingForMysqlCharset(String mysqlCharsetName)
    • getJavaEncodingForCollationIndex

      public static String getJavaEncodingForCollationIndex(Integer collationIndex, String javaEncoding)
    • getJavaEncodingForCollationIndex

      public static String getJavaEncodingForCollationIndex(Integer collationIndex)
    • getNumberOfCharsetsConfigured

      static final int getNumberOfCharsetsConfigured()
    • getCharacterEncodingForErrorMessages

      static final String getCharacterEncodingForErrorMessages(ConnectionImpl conn) throws SQLException
      Returns the character encoding for error messages returned from the server. Doesn't return useful values other than Cp1252 until the driver has gone through initialization phase and determined server configuration, as not enough information is available to make an intelligent decision until then.
      Parameters:
      conn - the connection to the MySQL server
      Returns:
      the Java encoding name that error messages use
      Throws:
      SQLException - if determination of the character encoding fails
    • requiresEscapeEasternUnicode

      static final boolean requiresEscapeEasternUnicode(String javaEncodingName)
    • isMultibyteCharset

      public static final boolean isMultibyteCharset(String javaEncodingName)
      Character sets that we can't convert ourselves.
      Parameters:
      javaEncodingName -
    • getMblen

      public static int getMblen(String charsetName)