*
* @param selectedFields Description of the Parameter
*/
private void DoExport(boolean[] selectedFields) {
//setup the csv printer
CSVPrint printer;
OutputStream out;
//create the export
String sSelectString = getSelectString(selectedFields, fromDate, toDate);
WorkingDialog workDialog = new WorkingDialog(null);
workDialog.setVisible(true);
workDialog.SetProgress(0);
try {
out = new FileOutputStream(outputFile);
if (isExcel) {
printer = new ExcelCSVPrinter(out);
} else {
printer = new CSVPrinter(out);
}
printer.changeDelimiter(delimiter);
DataConnection dc = DataConnection.getInstance(view);
if (dc == null || !dc.bIsConnectionMade) {
return;
}
Statement st = dc.con.createStatement();
ResultSet rs = st.executeQuery(dc.filterSQL(sSelectString));
ResultSetMetaData rsmd = rs.getMetaData();
if (rsmd == null) {
return;
}
int iNumColumns = rsmd.getColumnCount();
String[] outputStrings = new String[iNumColumns];
//count how many rows
int numRows = 0;
if (rs.next()) {
rs.last();
numRows = rs.getRow();
}
rs.beforeFirst();
//print out the rows
int rowCountShowProgress = 0;
int rowNum = 0;
while (rs.next()) {
rowNum++;
rowCountShowProgress++;
if (rowCountShowProgress >= 10) {
workDialog.SetProgress(rowNum * 100 / numRows);
rowCountShowProgress = 0;
}
for (int i = 1; i <= iNumColumns; i++) {
switch (rsmd.getColumnType(i)) {
case Types.VARCHAR:
outputStrings[i - 1] = rs.getString(i);
if (outputStrings[i - 1] == null) {
outputStrings[i - 1] = "";
}
if (rsmd.getColumnName(i).equals("TypeName")) {
//it needs to be translated...
outputStrings[i - 1] = Translator.getTranslation(outputStrings[i - 1]);
}
break;
case Types.INTEGER:
outputStrings[i - 1] = formatNumPane.numPanels[formatNumPane.SHOW_INTEGER].format(new Integer(rs.getInt(i)));
break;
case Types.NUMERIC:
case Types.REAL:
case Types.FLOAT:
case Types.DECIMAL:
case Types.DOUBLE:
outputStrings[i - 1] = formatNumPane.numPanels[formatNumPane.SHOW_WHOLE_NUMBER].format(new Double(rs.getDouble(i)));
break;
case Types.DATE:
outputStrings[i - 1] = formatNumPane.numPanels[formatNumPane.SHOW_DATE].format(rs.getDate(i));
break;
default:
outputStrings[i - 1] = StringBinaryConverter.BinaryToString(
rs.getBytes(i));
break;
}
Log.log(Log.DEBUG, this, "outputStrings[i-1]=" + outputStrings[i - 1]);
}
//send to the output
printer.println(outputStrings);
}
out.close();
} catch (Exception e) {
Log.log(Log.ERROR, this, "Error printing CSV file=" + e);
}