Class CharsetMapping
java.lang.Object
com.mysql.jdbc.CharsetMapping
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
FieldsModifier and TypeFieldDescriptionstatic final Map<String, MysqlCharset> static final MysqlCharset[]static final String[]static final Stringstatic final intstatic final intstatic final intstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static final StringReturns the character encoding for error messages returned from the server.static intgetCollationIndexForJavaEncoding(String javaEncoding, Connection conn) static StringgetJavaEncodingForCollationIndex(Integer collationIndex) static StringgetJavaEncodingForCollationIndex(Integer collationIndex, String javaEncoding) static StringgetJavaEncodingForMysqlCharset(String mysqlCharsetName) static StringgetJavaEncodingForMysqlCharset(String mysqlCharsetName, String javaEncoding) MySQL charset could map to several Java encodings.static intstatic final StringgetMysqlCharsetForJavaEncoding(String javaEncoding, Connection conn) static StringgetMysqlCharsetNameForCollationIndex(Integer collationIndex) (package private) static final intstatic final booleanisMultibyteCharset(String javaEncodingName) Character sets that we can't convert ourselves.(package private) static final booleanrequiresEscapeEasternUnicode(String javaEncodingName)
-
Field Details
-
MAP_SIZE
public static final int MAP_SIZE- See Also:
-
COLLATION_INDEX_TO_COLLATION_NAME
-
COLLATION_INDEX_TO_CHARSET
-
CHARSET_NAME_TO_CHARSET
-
CHARSET_NAME_TO_COLLATION_INDEX
-
UTF8MB4_INDEXES
-
NOT_USED
- See Also:
-
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
-
getJavaEncodingForMysqlCharset
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
-
getJavaEncodingForCollationIndex
-
getJavaEncodingForCollationIndex
-
getNumberOfCharsetsConfigured
static final int getNumberOfCharsetsConfigured() -
getCharacterEncodingForErrorMessages
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
-
isMultibyteCharset
Character sets that we can't convert ourselves.- Parameters:
javaEncodingName-
-
getMblen
-