java调用kettle4.2数据库型资料库中的转换
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryDirectoryInte易做图ce;
import org.pentaho.di.repository.kdr.KettleDatabaseRepository;
import org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
/**
* <p>Title: java调用kettle4.2数据库型资料库中的转换</p>
* <p>Description: </p>
* <p>Copyright: Copyright () 2012</p>
* @author 舵手
* @version
*/
public class ExecRepositoryTrans {
private static String transName = "Trans";
public static void main(String[] args) {
try {
KettleEnvironment.init();
KettleDatabaseRepository repository = new KettleDatabaseRepository();
DatabaseMeta databaseMeta = new DatabaseMeta("repository", "MSSQL","Native","192.169.0.146", "repository", "1433", "sa", "sa");
KettleDatabaseRepositoryMeta kettleDatabaseMeta = new KettleDatabaseRepositoryMeta("repository", "ERP", "Transformation description",databaseMeta );
repository.init(kettleDatabaseMeta);
repository.connect("admin","admin");
RepositoryDirectoryInte易做图ce directory = repository.loadRepositoryDirectoryTree();
TransMeta transformationMeta = ((Repository) repository).loadTransformation(transName, directory, null, true, null ) ;
Trans trans = new Trans( transformationMeta );
//trans.setParameterValue( parameterName, parameterValue);
trans.execute(null);
trans.waitUntilFinished();
if ( trans.getErrors() > 0 ) {
System.out.println("Error running transformation.");
}else{
System.out.println("Transformation run successfully.");
}
} catch (KettleException e) {
e.printStackTrace(); www.zzzyk.com
}
}
}
补充:软件开发 , Java ,