【Spark】java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long

【Spark】java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long,第1张

【Spark】java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
报错
Exception in thread "main" java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
	at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1023)
	at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3451)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2443)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2213)
	at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:797)
	at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
	at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$$anonfun$createConnectionFactory$2.apply(JdbcUtils.scala:65)
	at org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$$anonfun$createConnectionFactory$2.apply(JdbcUtils.scala:56)
	at org.apache.spark.sql.DataframeWriter.jdbc(DataframeWriter.scala:408)
	at task_hotel01_subjob2$.main(task_hotel01_subjob2.scala:55)
	at task_hotel01_subjob2.main(task_hotel01_subjob2.scala)

解决

主要原因:数据库版本与mysql连接驱动不匹配问题

因为本人本地数据库是mysql 8.x,虚拟机数据库是5.x,用的mysql连接驱动5.x版本,所以本地运行出现此问题,更换为8.x即可。






    mysql
    mysql-connector-java
    8.0.11


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5706048.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存