1.创建kettle脚本,并且可以成功运行转换,数据库连接也没问题!
2.Java代码
String fileName = "C:\\Users\\GaoHao\\Desktop\\Text\\ct_test.ktr";
System.out.println("-----------");
KettleEnvironment.init();
TransMeta transMeta = new TransMeta(fileName);
Trans trans = new Trans(transMeta);
trans.execute(null);
trans.waitUntilFinished();
3.报错信息
2022/03/09 12:31:39 - 表输出.0 - ERROR (version 9.0.0.0-423, build 9.0.0.0-423 from 2020-01-31 04.53.04 by buildguy) : An error occurred intialising this step:
2022/03/09 12:31:39 - 表输出.0 - Error occurred while trying to connect to the database
2022/03/09 12:31:39 - 表输出.0 -
2022/03/09 12:31:39 - 表输出.0 - Driver class 'org.gjt.mm.mysql.Driver' could not be found, make sure the 'MySQL' driver (jar file) is installed.
2022/03/09 12:31:39 - 表输出.0 - org.gjt.mm.mysql.Driver
2022/03/09 12:31:39 - 表输出.0 - ERROR (version 9.0.0.0-423, build 9.0.0.0-423 from 2020-01-31 04.53.04 by buildguy) : 错误初始化步骤[表输出]
2022/03/09 12:31:39 - ct_test - ERROR (version 9.0.0.0-423, build 9.0.0.0-423 from 2020-01-31 04.53.04 by buildguy) : 步骤 [表输出.0] 初始化失败!
2022/03/09 12:31:39 - 表输出.0 - ERROR (version 9.0.0.0-423, build 9.0.0.0-423 from 2020-01-31 04.53.04 by buildguy) : Unexpected error rolling back the database connection.
2022/03/09 12:31:39 - 表输出.0 - ERROR (version 9.0.0.0-423, build 9.0.0.0-423 from 2020-01-31 04.53.04 by buildguy) : org.pentaho.di.core.exception.KettleDatabaseException:
2022/03/09 12:31:39 - 表输出.0 - Unable to get database metadata from this database connection
2022/03/09 12:31:39 - 表输出.0 -
2022/03/09 12:31:39 - 表输出.0 - Error connecting to database [ct_test]
2022/03/09 12:31:39 - 表输出.0 -
2022/03/09 12:31:39 - 表输出.0 -
2022/03/09 12:31:39 - 表输出.0 - at org.pentaho.di.core.database.Database.getDatabaseMetaData(Database.java:3126)
2022/03/09 12:31:39 - 表输出.0 - at org.pentaho.di.core.database.Database.rollback(Database.java:906)
2022/03/09 12:31:39 - 表输出.0 - at org.pentaho.di.core.database.Database.rollback(Database.java:898)
2022/03/09 12:31:39 - 表输出.0 - at org.pentaho.di.trans.steps.tableoutput.TableOutput.dispose(TableOutput.java:625)
2022/03/09 12:31:39 - 表输出.0 - at org.pentaho.di.trans.Trans.prepareExecution(Trans.java:1257)
2022/03/09 12:31:39 - 表输出.0 - at org.pentaho.di.trans.Trans.execute(Trans.java:751)
2022/03/09 12:31:39 - 表输出.0 - at com.ct.test.kettle.KettleDemo.main(KettleDemo.java:32)
2022/03/09 12:31:39 - 表输出.0 - Caused by: org.pentaho.di.core.exception.KettleDatabaseException:
2022/03/09 12:31:39 - 表输出.0 - Error connecting to database [ct_test]
2022/03/09 12:31:39 - 表输出.0 -
2022/03/09 12:31:39 - 表输出.0 - at org.pentaho.di.core.database.Database.getDatabaseMetaData(Database.java:3120)
2022/03/09 12:31:39 - 表输出.0 - ... 6 more
Exception in thread "main" org.pentaho.di.core.exception.KettleException:
无法初始化至少一个步骤. 执行无法开始!
4.解决办法
需要单独添加mysql-connector-java-5.1.47-bin.jar这个依赖。
jar包下载地址:http://www.java2s.com/Code/Jar/m/Downloadmysqlconnectorjava5123binjar.htm
运行成功!