kettle导入csv文件至数据库表Incorrect datetime value问题

用Kettle将csv文件导入至数据库表中,简单流程如下:
在这里插入图片描述
建立好【CSV文件输入】->【插入/更新】转换后,进行测试,运行报如下错误:

	2019/07/16 15:01:45 - 插入 / 更新.0 - ERROR (version 8.3.0.0-371, build 8.3.0.0-371 from 2019-06-11 	11.09.08 by buildguy) : Error in step, asking everyone to stop because of:
	2019/07/16 15:01:45 - 插入 / 更新.0 - ERROR (version 8.3.0.0-371, build 8.3.0.0-371 from 2019-06-11 1.09.08 by buildguy) : org.pentaho.di.core.exception.KettleDatabaseException: 
	2019/07/16 15:01:45 - 插入 / 更新.0 - Error inserting/updating row
	2019/07/16 15:01:45 - 插入 / 更新.0 - Data truncation: Incorrect datetime value: '16/7/2019 14:28:32' for column 'create_time' at row 1
	2019/07/16 15:01:45 - 插入 / 更新.0 - 
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at org.pentaho.di.core.database.Database.insertRow(Database.java:1324)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at org.pentaho.di.core.database.Database.insertRow(Database.java:1248)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at org.pentaho.di.core.database.Database.insertRow(Database.java:1236)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at 	org.pentaho.di.core.database.Database.insertRow(Database.java:1224)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at org.pentaho.di.trans.steps.insertupdate.InsertUpdate.lookupValues(InsertUpdate.java:114)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at org.pentaho.di.trans.steps.insertupdate.InsertUpdate.processRow(InsertUpdate.java:299)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at java.lang.Thread.run(Thread.java:748)
	2019/07/16 15:01:45 - 插入 / 更新.0 - Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '16/7/2019 14:28:32' for column 'create_time' at row 1
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3968)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	at org.pentaho.di.core.database.Database.insertRow(Database.java:1291)
	2019/07/16 15:01:45 - 插入 / 更新.0 - 	... 7 more	

遂查看字段数据类型,发现create_time字段为String类型,改为Date类型后继续测试,再次报错:

2019/07/16 15:10:14 - 插入 / 更新.0 - create_time String : couldn't convert string [16/7/2019 14:28:32] to a date using format [yyyy/MM/dd HH:mm:ss.SSS] on offset location 18
2019/07/16 15:10:14 - 插入 / 更新.0 - 16/7/2019 14:28:32
2019/07/16 15:10:14 - 插入 / 更新.0 - 	at org.pentaho.di.core.database.Database.setValues(Database.java:1081)
2019/07/16 15:10:14 - 插入 / 更新.0 - 	at org.pentaho.di.trans.steps.insertupdate.InsertUpdate.lookupValues(InsertUpdate.java:83)
2019/07/16 15:10:14 - 插入 / 更新.0 - 	at org.pentaho.di.trans.steps.insertupdate.InsertUpdate.processRow(InsertUpdate.java:299)
2019/07/16 15:10:14 - 插入 / 更新.0 - 	at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62)
2019/07/16 15:10:14 - 插入 / 更新.0 - 	at java.lang.Thread.run(Thread.java:748)

可以看出String转成Date后时间格式不正确,这里通过【转换】中的【字段选择】功能来修改时间格式。
在这里插入图片描述
添加【字段选择】步骤后双击编辑,点击元数据,在行中添加需要改变元数据的字段,选择字段类型为Date(输入端字段类型不要修改),设置时间格式,点击确定。
在这里插入图片描述
再次运行,csv文件数据成功导入数据库。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值