private void buildCollationMapping() throws SQLException {
HashMap<Integer, String> javaCharset = null;
if (versionMeetsMinimum(4, 1, 0)) {
TreeMap<Long, String> sortedCollationMap = null;
HashMap<Integer, String> customCharset = null;
HashMap<String, Integer> customMblen = null;
if (getCacheServerConfiguration()) {
synchronized (serverCollationByUrl) {
sortedCollationMap = (TreeMap<Long, String>) serverCollationByUrl.get(getURL());
javaCharset = (HashMap<Integer, String>) serverJavaCharsetByUrl.get(getURL());
customCharset = (HashMap<Integer, String>) serverCustomCharsetByUrl.get(getURL());
customMblen = (HashMap<String, Integer>) serverCustomMblenByUrl.get(getURL());
}
}
java.sql.Statement stmt = null;
java.sql.ResultSet results = null;
try {
if (sortedCollationMap == null) {
sortedCollationMap = new TreeMap<Long, String>();
javaCharset = new HashMap<Integer, String>();
customCharset = new HashMap<Integer, String>();
customMblen = new HashMap<String, Integer>();
stmt = getMetadataSafeStatement();
try {
results = stmt.executeQuery("SHOW COLLATION");
if (versionMeetsMinimum(5, 0, 0)) {
Util.resultSetToMap(sortedCollationMap, results, 3, 2);
} else {
while (results.next()) {
sortedCollationMap.put(results.getLong(3), results.getString(2));
}
}
} catch (SQLException ex) {
if (ex.getErrorCode() != MysqlErrorNumbers.ER_MUST_CHANGE_PASSWORD || getDisconnectOnExpiredPasswords()) {
throw ex;
}
}
for (Iterator<Map.Entry<Long, String>> indexIter = sortedCollationMap.entrySet().iterator(); indexIter.hasNext();) {
Map.Entry<Long, String> indexEntry = indexIter.next();
int collationIndex = indexEntry.getKey().intValue();
当步骤以 “INT collationIndex = indexEntry.getKey()的intValue();”,它抛出ClassCastException异常。
有没有人见面之前,如何解决呢?谢谢...
一个老问题了一点,但昨天我们解决同样的事情。它原来是由于我们使用MySQL V8但我的SQL连接器是V5。当被安装了MySQL V5问题就走了。
检查数据库和连接器版本,以确保兼容性。