Domanda

I have a method for checking the attendance of the employees. The firstnames,lastnames, position of employees are retrieve from a database. the daily attendance method works fine. now, I also have a method that creates a monthly attendance report from the daily attendance method. it also retrieves the data in the database. In querying, I used a pivot. It doesn't work. The error says that it has an error in the from clause. but when I test that query in ms access, It works perfectly. Can everyone help me with this. this is my code.

private void attendanceView() throws ClassNotFoundException{
        String query ="TRANSFORM COUNT(attendance.present)SELECT employees.ID,employees.firstName,employees.lastName,employees.position,employees.rate FROM employees LEFT JOIN attendance ON employees.ID = attendance.empID GROUP BY employees.ID,employees.firstName,employees.lastName,employees.position,employees.rate PIVOT attendance.dateAttended";
       Object[][] result = connectToDB(query);
       monthlyAttendanceTable.setModel(new javax.swing.table.DefaultTableModel(
               result, new String [] {"Employee ID","First Name","Last Name", "Position", "Rate","",""}
       )
       {
           Class[] types = new Class [] {
               java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class,java.lang.Integer.class,java.lang.Integer.class,java.lang.String.class
           };
           boolean[] canEdit = new boolean [] {
               false, false, false, false, false, false, false, false, false,false
           };

           public Class getColumnClass(int columnIndex) {
               return types [columnIndex];
           }

           public boolean isCellEditable(int rowIndex, int columnIndex) {

               return canEdit [columnIndex];
           }
       });
    }

I've read from some resources that the result set can be inserted to a excel file. Can anyone help me with this? I'm accessing the database through the connectToDB() method, I want to insert to the excel file the pivot query result.

È stato utile?

Soluzione

You can use EasyXLS library to export the result set to the Excel file. Check some source code sample here.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top