etl结合java的例子

1.新建Java测试类,导出Jar包,放在kettle目录中的libext文件中

  1. package test;
  2. public class Test{
  3. public static final String getMyName(String name){
  4. return name+"12345";
  5. }
  6. }

2.抽数据--经过java处理--输出文件到桌面

etl结合java的例子

  1. import test.Test;
  2. public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
  3. {
  4. Object[] r = getRow();
  5. if (r == null) {
  6. setOutputDone();
  7. return false;
  8. }
  9. if (first)
  10. {
  11. first = false;
  12. }
  13. // It is always safest to call createOutputRow() to ensure that your output row's Object[] is large
  14. // enough to handle any new fields you are creating in this step.
  15. //r = createOutputRow(r, outputRowSize);
  16. /* TODO: Your code here. (See Sample)
  17. / Get the value from an input field
  18. String foobar = get(Fields.In, "a_fieldname").getString(r);
  19. foobar += "bar";
  20. // Set a value in a new output field
  21. get(Fields.Out, "output_fieldname").setValue(r, foobar);
  22. */
  23. //调用jar
  24. String foobar = get(Fields.In, "ENAME").getString(r); //输入参数
  25. foobar += Test.getMyName("我是谁的水");
  26. get(Fields.Out, "ENAME").setValue(r, foobar);
  27. //获取参数
  28. String AGEField = getParameter("AGE");
  29. get(Fields.Out, "AGE").setValue(r, AGEField); //输出参数
  30. // Send the row on to the next step.
  31. putRow(data.outputRowMeta, r);
  32. return true;
  33. }

                  来源:http://programmer.blog.51cto.com/2859493/1164002

上一篇:C# 常用日期函数


下一篇:[C#]AccessUtils