⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 charsetmapping.java

📁 开发MySql数据库的最新JDBC驱动。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		INDEX_TO_COLLATION[194] = "utf8_latvian_ci";		INDEX_TO_COLLATION[195] = "utf8_romanian_ci";		INDEX_TO_COLLATION[196] = "utf8_slovenian_ci";		INDEX_TO_COLLATION[197] = "utf8_polish_ci";		INDEX_TO_COLLATION[198] = "utf8_estonian_ci";		INDEX_TO_COLLATION[199] = "utf8_spanish_ci";		INDEX_TO_COLLATION[200] = "utf8_swedish_ci";		INDEX_TO_COLLATION[201] = "utf8_turkish_ci";		INDEX_TO_COLLATION[202] = "utf8_czech_ci";		INDEX_TO_COLLATION[203] = "utf8_danish_ci";		INDEX_TO_COLLATION[204] = "utf8_lithuanian_ci ";		INDEX_TO_COLLATION[205] = "utf8_slovak_ci";		INDEX_TO_COLLATION[206] = "utf8_spanish2_ci";		INDEX_TO_COLLATION[207] = "utf8_roman_ci";		INDEX_TO_COLLATION[208] = "utf8_persian_ci";		INDEX_TO_COLLATION[209] = "utf8_esperanto_ci";		INDEX_TO_COLLATION[210] = "utf8_hungarian_ci";				Map tempMap = new HashMap();				tempMap.put("czech", "latin2");		tempMap.put("danish", "latin1");		tempMap.put("dutch", "latin1");		tempMap.put("english", "latin1");		tempMap.put("estonian", "latin7");		tempMap.put("french", "latin1");		tempMap.put("german", "latin1");		tempMap.put("greek", "greek");		tempMap.put("hungarian", "latin2");		tempMap.put("italian", "latin1");		tempMap.put("japanese", "ujis");		tempMap.put("japanese-sjis", "sjis");		tempMap.put("korean", "euckr");		tempMap.put("norwegian", "latin1");		tempMap.put("norwegian-ny", "latin1");		tempMap.put("polish", "latin2");		tempMap.put("portuguese", "latin1");		tempMap.put("romanian", "latin2");		tempMap.put("russian", "koi8r");		tempMap.put("serbian", "cp1250");		tempMap.put("slovak", "latin2");		tempMap.put("spanish", "latin1");		tempMap.put("swedish", "latin1");		tempMap.put("ukrainian", "koi8u");				ERROR_MESSAGE_FILE_TO_MYSQL_CHARSET_MAP = 			Collections.unmodifiableMap(tempMap);	}	public final static String getJavaEncodingForMysqlEncoding(String mysqlEncoding,			Connection conn) throws SQLException {		
		if (conn != null && conn.versionMeetsMinimum(4, 1, 0) && 
				"latin1".equalsIgnoreCase(mysqlEncoding)) {
			return "Cp1252";
		}
		
		return (String) MYSQL_TO_JAVA_CHARSET_MAP.get(mysqlEncoding);	}	public final static String getMysqlEncodingForJavaEncoding(String javaEncodingUC,			Connection conn) throws SQLException {		List mysqlEncodings = (List) CharsetMapping.JAVA_UC_TO_MYSQL_CHARSET_MAP				.get(javaEncodingUC);		;		if (mysqlEncodings != null) {			Iterator iter = mysqlEncodings.iterator();			VersionedStringProperty versionedProp = null;			while (iter.hasNext()) {				VersionedStringProperty propToCheck = (VersionedStringProperty) iter						.next();				if (conn == null) {					// Take the first one we get					return propToCheck.toString();				}				if (versionedProp != null && !versionedProp.preferredValue) {					if (versionedProp.majorVersion == propToCheck.majorVersion							&& versionedProp.minorVersion == propToCheck.minorVersion							&& versionedProp.subminorVersion == propToCheck.subminorVersion) {						return versionedProp.toString();					}				}				if (propToCheck.isOkayForVersion(conn)) {					if (propToCheck.preferredValue) {						return propToCheck.toString();					}					versionedProp = propToCheck;				} else {					break;				}			}			if (versionedProp != null) {				return versionedProp.toString();			}		}		return null;	}	final static int getNumberOfCharsetsConfigured() {		return MYSQL_TO_JAVA_CHARSET_MAP.size() / 2; // because we UC every														// key	}	/**	 * 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.	 * 	 * @param conn the connection to the MySQL server	 * @return the Java encoding name that error messages use	 * @throws SQLException if determination of the character encoding fails	 */	final static String getCharacterEncodingForErrorMessages(Connection conn) throws SQLException {		String errorMessageFile = conn.getServerVariable("language");				if (errorMessageFile == null || errorMessageFile.length() == 0) {			// punt			return "Cp1252";		}				int endWithoutSlash = errorMessageFile.length();				if (errorMessageFile.endsWith("/") || errorMessageFile.endsWith("\\")) {			endWithoutSlash--;		}					int lastSlashIndex = errorMessageFile.lastIndexOf('/', endWithoutSlash - 1);				if (lastSlashIndex == -1) {			lastSlashIndex = errorMessageFile.lastIndexOf('\\', endWithoutSlash - 1);		}				if (lastSlashIndex == -1) {			lastSlashIndex = 0;		}				if (lastSlashIndex == endWithoutSlash || endWithoutSlash < lastSlashIndex) {			// punt			return "Cp1252";		}				errorMessageFile = errorMessageFile.substring(lastSlashIndex + 1, endWithoutSlash);				String errorMessageEncodingMysql = (String)ERROR_MESSAGE_FILE_TO_MYSQL_CHARSET_MAP.get(errorMessageFile);				if (errorMessageEncodingMysql == null) {			// punt			return "Cp1252";		}				String javaEncoding = getJavaEncodingForMysqlEncoding(errorMessageEncodingMysql, conn);				if (javaEncoding == null) {			// punt			return "Cp1252";		}				return javaEncoding;	}		final static boolean isAliasForSjis(String encoding) {		return ("SJIS".equalsIgnoreCase(encoding)				|| "WINDOWS-31J".equalsIgnoreCase(encoding)				|| "MS932".equalsIgnoreCase(encoding)				|| "SHIFT_JIS".equalsIgnoreCase(encoding) || "CP943"				.equalsIgnoreCase(encoding));	}	final static boolean isMultibyteCharset(String javaEncodingName) {		String javaEncodingNameUC = javaEncodingName				.toUpperCase(Locale.ENGLISH);		return MULTIBYTE_CHARSETS.containsKey(javaEncodingNameUC);	}	private static void populateMapWithKeyValuePairs(String configKey,			Map mapToPopulate, boolean addVersionedProperties,			boolean addUppercaseKeys) {		String javaToMysqlConfig = CHARSET_CONFIG.getProperty(configKey);		if (javaToMysqlConfig != null) {			List mappings = StringUtils.split(javaToMysqlConfig, ",", true);			if (mappings != null) {				Iterator mappingsIter = mappings.iterator();				while (mappingsIter.hasNext()) {					String aMapping = (String) mappingsIter.next();					List parsedPair = StringUtils.split(aMapping, "=", true);					if (parsedPair.size() == 2) {						String key = parsedPair.get(0).toString();						String value = parsedPair.get(1).toString();						if (addVersionedProperties) {							List versionedProperties = (List) mapToPopulate									.get(key);							if (versionedProperties == null) {								versionedProperties = new ArrayList();								mapToPopulate.put(key, versionedProperties);							}							VersionedStringProperty verProp = new VersionedStringProperty(									value);							versionedProperties.add(verProp);							if (addUppercaseKeys) {								String keyUc = key.toUpperCase(Locale.ENGLISH);								versionedProperties = (List) mapToPopulate										.get(keyUc);								if (versionedProperties == null) {									versionedProperties = new ArrayList();									mapToPopulate.put(keyUc,											versionedProperties);								}								versionedProperties.add(verProp);							}						} else {							mapToPopulate.put(key, value);							if (addUppercaseKeys) {								mapToPopulate.put(key										.toUpperCase(Locale.ENGLISH), value);							}						}					} else {						throw new RuntimeException(								"Syntax error in Charsets.properties "										+ "resource for token \"" + aMapping										+ "\".");					}				}			} else {				throw new RuntimeException("Missing/corrupt entry for \""						+ configKey + "\" in Charsets.properties.");			}		} else {			throw new RuntimeException("Could not find configuration value "					+ "\"" + configKey + "\" in Charsets.properties resource");		}	}}class VersionedStringProperty {	int majorVersion, minorVersion, subminorVersion;	boolean preferredValue = false;	String propertyInfo;	VersionedStringProperty(String property) {		property = property.trim();		if (property.startsWith("*")) {			property = property.substring(1);			preferredValue = true;		}		if (property.startsWith(">")) {			property = property.substring(1);			int charPos = 0;			for (charPos = 0; charPos < property.length(); charPos++) {				char c = property.charAt(charPos);				if (!Character.isWhitespace(c) && !Character.isDigit(c)						&& c != '.') {					break;				}			}			String versionInfo = property.substring(0, charPos);			List versionParts = StringUtils.split(versionInfo, ".", true);			majorVersion = Integer.parseInt(versionParts.get(0).toString());			if (versionParts.size() > 1) {				minorVersion = Integer.parseInt(versionParts.get(1).toString());			} else {				minorVersion = 0;			}			if (versionParts.size() > 2) {				subminorVersion = Integer.parseInt(versionParts.get(2)						.toString());			} else {				subminorVersion = 0;			}			propertyInfo = property.substring(charPos);		} else {			majorVersion = minorVersion = subminorVersion = 0;			propertyInfo = property;		}	}	VersionedStringProperty(String property, int major, int minor, int subminor) {		propertyInfo = property;		majorVersion = major;		minorVersion = minor;		subminorVersion = subminor;	}	boolean isOkayForVersion(Connection conn) throws SQLException {		return conn.versionMeetsMinimum(majorVersion, minorVersion,				subminorVersion);	}	public String toString() {		return propertyInfo;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -