return ans;
}
public void doExport(String sqlStatement, File fHandle) throws Exception{
Rep("Will execute <"+sqlStatement+">");
TABLEDATADocument doc = TABLEDATADocument.Factory.newInstance();
TABLEDATA tableData = doc.addNewTABLEDATA();
EXPORTINFO exportInfo = tableData.addNewEXPORTINFO();
exportInfo.setSTATEMENT(sqlStatement);
exportInfo.setTIMESTAMP(Calendar.getInstance());
ResultSet prs = oraConnection.prepareCall(sqlStatement).executeQuery();
ResultSetMetaData columns = prs.getMetaData();
int colCount = columns.getColumnCount();
Rep("Statement returns "+colCount+" columns");
String wColumns = "";
for(int i=0;i<colCount;i++){
COLUMNTYPE colType = exportInfo.addNewCOLUMNTYPE();
colType.setNAME(columns.getColumnName(i+1));
colType.setTYPE(columns.getColumnTypeName(i+1));
if(columns.getColumnTypeName(i+1).equalsIgnoreCase("DATE")){
colType.setFORMATMASK(DATE_FORMAT);
}
colType.setTABLENAME(columns.getTableName(i+1));
if(i==0){
wColumns = getNewColumn(columns,i+1);
} else {
wColumns = wColumns+","+getNewColumn(columns,i+1);
}
}
String newSql = sqlStatement.substring(sqlStatement.toUpperCase().indexOf(" FROM "));
newSql = "select "+wColumns+newSql;
Dbg(newSql);
ResultSet rs = oraConnection.prepareCall(newSql).executeQuery();
int line=0;
while(rs.next()){
line++;
ROW row = tableData.addNewROW();
Rep("Exporting record "+ line);
for(int i=0;i<colCount;i++){
COLUMN col = row.addNewCOLUMN();
col.setCOLUMNNAME(columns.getColumnName(i+1));
col.setDATA(getColumnData(rs,i+1,columns.getColumnTypeName(i+1)));
}
}
Rep("Finished!");
doc.save(fHandle);
}