I am new in Java and know about how to export data from mysql to export
My code as below :-
database code:-
private void setDynamicDate(LoginCountForm l_objForm) throws Exception {Connection l_objConnection = DataAccess.connectToDatabase();
Statement l_objStatement = l_objConnection.createStatement();
Statement l_objStatement1 = l_objConnection.createStatement();
String l_strQuery = "";
int m_noofdays = 0;
String d = "";
LoginCountBean bean = null;
LoginCountBean1 bean1 = null;
ArrayList lst = new ArrayList();
ArrayList lst1 = new ArrayList();
ArrayList date = new ArrayList();
List completeList = new ArrayList();
String m_strStartDate = SDCommonUtil.convertSDFormatToDBDate(l_objForm
.getM_strStartDate());
String m_strEndDate = SDCommonUtil.convertSDFormatToDBDate(l_objForm
.getM_strEndDate());
l_strQuery = "Select timestampdiff(day,'" + m_strStartDate + "','"
+ m_strEndDate + "')";
l_objStatement.executeQuery(l_strQuery);
ResultSet l_objRes = l_objStatement.getResultSet();
while (l_objRes.next()) {
m_noofdays = l_objRes.getInt(1);
m_noofdays = m_noofdays + 1;
}
for (int i = 0; i < m_noofdays; i++) {
l_strQuery = "select DATE_ADD('" + m_strStartDate + "',INTERVAL '"
+ i + "' DAY) as d";
l_objStatement.executeQuery(l_strQuery);
l_objRes = l_objStatement.getResultSet();
if (l_objRes != null) {
while (l_objRes.next()) {
bean = new LoginCountBean();
String date1 = l_objRes.getString("d");
bean.setM_strDynamicDate(date1);
date.add(date1);
lst.add(bean);
bean = null;
}
}
l_objForm.setL_lstDynamicDate(lst);
}
for (int i = 0; i < date.size(); i++) {
l_strQuery = "SELECT e.pernr,t.count FROM sales.empdetails e left join (SELECT pernr,count FROM sales.loginncntmst where date="
+ SDCommonUtil.convertBlankToNull(String.valueOf(date
.get(i)), true) + ") t on e.pernr=t.pernr";
System.out.println(l_strQuery);
l_objStatement.executeQuery(l_strQuery);
l_objRes = l_objStatement.getResultSet();
while (l_objRes.next()) {
bean1 = new LoginCountBean1();
bean1.setM_strDynamicDateCount(l_objRes.getString("count"));
if (bean1.getM_strDynamicDateCount() == null) {
bean1.setM_strDynamicDateCount("0");
}
bean1.setM_strEmployeeName(SDCommonUtil.convertValuesForValueAndID(l_objStatement1,
"sales.empdetails", "pernr", "ename",
SDCommonUtil.convertNullToBlank(l_objRes.getString("pernr"), false), true));
bean1.setM_strDepartment(SDCommonUtil
.convertValuesForValueAndID(l_objStatement1,
"sales.empdetails", "pernr", "department",
SDCommonUtil.convertBlankToNull(l_objRes
.getString("pernr"), false), true));
lst1.add(bean1);
bean1 = null;
}
completeList.add(lst1);
lst1 = new ArrayList();
}
l_objForm.setL_lstLoginCount(completeList);
l_objConnection.close();
}
in the above code i was receive 379 row from table know i want to handle in excel my excel code are as beloe :-
public void exportToExcel(LoginCountForm l_objForm,
HttpServletResponse response) throws Exception {
ArrayList dataList = new ArrayList
ArrayList dataList1 = new ArrayList
ArrayList dataList2 = new ArrayList
ArrayList dataList3 = new ArrayList
ArrayList headers = new ArrayList();
// File file123 = new File("/tmp/Employee Leave Report.xls");
String contextPath = getServlet().getServletContext().getRealPath("/");
File file123 = new File(contextPath + "/Login Count Day Wise.xls");
// File file123 = new File("E://Vip//Employee Leave Report.xls");
String m_strFileName = "Login Count Day Wise.xls";
headers.add("Employee Name");
headers.add("Department");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Employee Login Count Daywise");
int rowIdx = 0;
int cellIdx = 0;
int a[] = new int[headers.size()];
HSSFRow hssfHeader = sheet.createRow(rowIdx);
sheet.setColumnWidth(0, 4200);
sheet.setColumnWidth(1, 4200);
HSSFFont font = wb.createFont();
font.setFontName("Calibri");
font.setFontHeightInPoints((short) 11);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cellStyle.setFont(font);
int m = 0;
for (Iterator cells = headers.iterator(); cells.hasNext();) {
String data = (String) cells.next();
HSSFCell hssfCell = hssfHeader.createCell(cellIdx++);
hssfCell.setCellStyle(cellStyle);
hssfCell.setCellValue(data);
}
for (int i = 0; i < l_objForm.getL_lstDynamicDate().size(); i++) {
LoginCountBean reportBean = (LoginCountBean) l_objForm
.getL_lstDynamicDate().get(i);
ArrayList

Replies
Know the answer? Post it — somebody with the same question will find it here.