zoukankan      html  css  js  c++  java
  • 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处理--输出文件到桌面

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

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

  • 相关阅读:
    常用经典SQL语句
    怎样找到PB打包所需要的dll和pbd文件?
    C#多线程参数传递
    Sqlserver 常用日期时间函数
    SQL Server:如何判断变量或字段是否为NULL
    用c#开发可供PB调用的COM组件
    ROW_NUMBER() OVER函数的基本用法用法
    SQL Server数据导入导出工具BCP详解
    IE下 Window.Open(url,name), name参数空格、符号问题
    数据库设计系列[05]多公司加入权限系统
  • 原文地址:https://www.cnblogs.com/kongxc/p/6242321.html
Copyright © 2011-2022 走看看