public static void main(String[] args) throws Exception
{
EnvUtil.environmentInit();
// Init the logging...
LogWriter log = LogWriter.getInstance(\true, LogWriter.LOG_LEVEL_DETAILED);
// Load the Kettle steps & plugins
StepLoader stloader = StepLoader.getInstance();
if (!stloader.read())
{
log.logError(\ \loading Kettle steps & plugins... stopping now!\
return;
}
// The parameters we want, optionally this can be
String fileName = \
String transformationName = \
String sourceDatabaseName = \
String sourceTableName = \
String sourceFields[] = {
\
};
String targetDatabaseName = \
String targetTableName = \
String targetFields[] = {
\
};
// Generate the transformation.
TransMeta transMeta = TransBuilder.buildCopyTable(
transformationName,
sourceDatabaseName,
sourceTableName,
sourceFields,
targetDatabaseName,
targetTableName,
targetFields
);
// Save it as a file:
String xml = transMeta.getXML();
DataOutputStream dos = new DataOutputStream(new File(fileName)));
dos.write(xml.getBytes(\
FileOutputStream(new
dos.close();
System.out.println(\
// OK, What's the SQL we need to execute to generate the target table?
String sql = transMeta.getSQLStatementsString();
// Execute the SQL on the target table:
Database targetDatabase = Database(transMeta.findDatabase(targetDatabaseName));
targetDatabase.connect();
targetDatabase.execStatements(sql);
// Now execute the transformation...
Trans trans = new Trans(log, transMeta);
trans.execute(null);
trans.waitUntilFinished();
// For testing/repeatability, we drop the target table again
/* modi by chq([link=http://www.chq.name]www.chq.name[/link]) on 必删表
//targetDatabase.execStatement(\
targetDatabase.disconnect();
}
new 2006.07.20 不 }