Hi Ricardo,
I haven't tried , let's try saving the output to an EXCEL file with Apache POI.
In order to do this you need to have the POI jar file from Apache.
Step 1: Generate the Results from the DB and store them into an ArrayList (any Collection Object).
Step 2: Create the File
FileOutputStream fileOut = new FileOutputStream("sendOutPutAsEmail.xls"

;
Setp 3: Create a HSSFWorkBook
HSSFWorkbook workBook = new HSSFWorkBook();
HSSFSheet sheet1 = workBook.createSheet("TestOutPut"

;
Setp 4: Create the Headers row in the XLS file. Use ResultSetMetaData of the Resultset
HSSFRow row = sheet1.createRow((short)0);
ResultSetMetaData columnNames = rs.getColumnNames();
for (int i=0; i<columnNames.size()+ 1; i++)
{
row.createCell((short)i).setCellValue(rsmd.getColumnName(i));
}
Setp 5: Load the data into the cells
ArrayList data = resultSetList;
// resultSetList is generated from Step 1
row = sheet1.createRow((short)(i+1));
for (int j=0; j<data.size(); j++)
{
String columnData = (String)data.get(j);
Row.createCell((short)j).setCellvalue(columnData);
}
Setp 6: Save the File and close
workBook.write(fileOut);
fileOut.close();
Setp 7: Attach the file you have generted in step 2 and send an E-Mail out.
Other way around. If your DB has the SMTP or POP setup you can actually send the E-Mail out form the DB. Generate an Excel file with SQL Query and send the file out.
Cheers,
Venu