不支持java.util.Date [英] java.util.Date is not supported

查看:112
本文介绍了不支持java.util.Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 RDD 写入 MYSQL ,其中 RDD 包含 java.util.Date 类型。

I want to write RDD to MYSQL, which RDD contains java.util.Date type.

rdd.map(f=> FeatureData(
           f.get("name").toString, 
           f.get("value").toString.toDouble, 
           f.get("time").asInstanceOf[Date],
           f.get("period").toString))
    .toDF()

在此 RDD 中,时间的键值也是 java.util.Date 并且它只是得到
的错误[请参阅嵌套异常:java.lang.UnsupportedOperationException:类型为java的模式。不支持util.Date

In this RDD the key of time's value type is also java.util.Date and it just get the error of [See nested exception: java.lang.UnsupportedOperationException: Schema for type java.util.Date is not supported

推荐答案

首先转换 java.util.Date java.sql.Date 。然后使用 java.sql.Date 的数据运行您的sql。示例代码:

At first convert java.util.Date to java.sql.Date. Then run your sql with the data of java.sql.Date. Sample code :

java.util.Date utilDate = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

更新:
AndreHolzner建议使用的java.sql.Timestamp 。我还没试过,但一般时间戳优于日期

Update: AndreHolzner suggested to use java.sql.Timestamp. I did not try it yet, but generally Timestamp is better than Date.

这篇关于不支持java.util.Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆