jdbc.ConnectionImpl.buildCollat ionMapping抛出ClassCastException

问题描述 投票:0回答:1
  1. 我用的是Tomcat的v8.0.39,mysql8,jdk1.8,MyBatis的v3.2.8。
  2. 当我第一次得到与DB,在MySQL连接器的Java-5.1.26.jar类com.mysql.jdbc.ConnectionImpl抛出ClassCastException连接:java.math.BigInteger中不能转换为java.lang.Long中
  3. 我尽量让断点检查,代码: 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 collat​​ionIndex = indexEntry.getKey()的intValue();”,它抛出ClassCastException异常。

有没有人见面之前,如何解决呢?谢谢...

java mysql jdbc
1个回答
0
投票

一个老问题了一点,但昨天我们解决同样的事情。它原来是由于我们使用MySQL V8但我的SQL连接器是V5。当被安装了MySQL V5问题就走了。

检查数据库和连接器版本,以确保兼容性。

© www.soinside.com 2019 - 2024. All rights reserved.