kettle入门教程
Posted yooy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kettle入门教程相关的知识,希望对你有一定的参考价值。
@Test
public void read() throws KettleException {
KettleEnvironment.init();
TransMeta transMeta = new TransMeta();
transMeta.setName("datesyn2");
//添加数据连接
DatabaseMeta dataBaseInput = new DatabaseMeta("Input", "mysql", "Native(JDBC)", "192.168.1.187", "tdir", "3306",
"root", "root");
transMeta.addDatabase(dataBaseInput);
//表输入
TableInputMeta tableInputMeta = new TableInputMeta();
tableInputMeta.setDatabaseMeta(transMeta.findDatabase("Input"));
tableInputMeta.setSQL("SELECT id, name, age FROM test");
StepMeta inputStep = new StepMeta("表输入",tableInputMeta);
inputStep.setLocation(50,50);
// inputStep.setDraw(true);
transMeta.addStep(inputStep);
inputStep.setDraw(true);
String xml =transMeta.getXML();
DataOutputStream dos = new DataOutputStream(KettleVFS.getOutputStream("D:/csv.ktr", false));
try {
dos.write(xml.getBytes(Const.XML_ENCODING));
dos.close();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//开始执行
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
trans.startThreads();
trans.waitUntilFinished();
if(trans.getErrors() > 0) {
System.out.println(">>>>>>>>>> ERROR");
}else {
System.out.println(">>>>>>>>>> SUCCESS ");
}
}
以上是关于kettle入门教程的主要内容,如果未能解决你的问题,请参考以下文章