$('form').submit(function ()
{
$.ajax({
method: 'POST',
url: 'dashboard/filter',
success: function (data) {
var percent=[];
var names=[];
var colors=[];
$.each(JSON.parse(data), function(index, report)
{
percent.push(report.count_percent)
});
$.each(JSON.parse(data), function(index, name)
{
names.push(name.resname)
});
$.each(names, function()
{
colors.push(getRandomColor())
});
// console.log(data);
globalChart.data.labels=names;
globalChart.data.datasets=percent;
globalChart.update();
}
});
return false;
});
public class EmployeeDAO
{
private Connection myCon;
public static EmployeeDAO empDao;
public EmployeeDAO()
{
try {
myCon=DriverManager.getConnection("jdbc:mysql://localhost:3306/xml_test","root","");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public List<Employee> getAllEmployees() throws SQLException, JAXBException
{
List<Employee> list=new ArrayList<>();
Statement statement=myCon.createStatement();
ResultSet result=statement.executeQuery("SELECT * FROM employees");
while(result.next())
{
Employee emp=convertXMLToEmployee(result);
list.add(emp);
}
return list;
}
private Employee convertXMLToEmployee(ResultSet result) throws SQLException, JAXBException
{
int id=result.getInt("id");
String data=result.getString("data");
int positionId=result.getInt("position_id");
StringReader sr = new StringReader(data);
JAXBContext jaxbContext = JAXBContext.newInstance(Employee.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Employee employee = (Employee) unmarshaller.unmarshal(sr);
employee.setId(id);
employee.setPositionId(positionId);
return employee;
}
}