使用Talend open studio  ,从mysql数据源中读取数据,将数据导出到excel文档,另外一个mysql数据库,和一个普通文件,遇到标题的错误,模型如下图所示:

java.lang.RuntimeException: Date pattern must be set for column update_time in the schema of component-LMLPHP

tMap将30.7中的每一个字段都要输出到excel字段中,如下图所示:

java.lang.RuntimeException: Date pattern must be set for column update_time in the schema of component-LMLPHP

但是其中有两个字段,update_time和last_msg_intime为date类型,到了excel中,应该设置为string类型。

java.lang.RuntimeException: Date pattern must be set for column update_time in the schema of component-LMLPHP

在toExcel中,将上述两个字段设置成string类型后,还是不够的,需要在映射的过程中将msyql的字段转换为字符串的操作,使用String.valueof(row1.update_time), string.valueof(row1.last_msg_intime)注意,这里不能够使用last_msg_intime.toString(),因为last_msg_intime有可能为空,这样就会报出空指针异常。

修改方法如下:

java.lang.RuntimeException: Date pattern must be set for column update_time in the schema of component-LMLPHP

java.lang.RuntimeException: Date pattern must be set for column update_time in the schema of component-LMLPHP

TOS会将模型直接生成java代码,生成代码如下:

java.lang.RuntimeException: Date pattern must be set for column update_time in the schema of component-LMLPHP

05-11 11:11