我还是编程新手。目前,我有一个程序来检查员工的出勤率。员工ID&从数据库中检索名称。员工的每日出勤率保存在数据库的考勤表中,其中的字段只有ID,empID,dateAttended," present",#34;加班"。现在,我想从考勤表中检索所有值。起初,我可以很好地检索值,但是在我添加" a.dateAttended"和#34; a.Present",我得到了这个例外。关于我如何解决这个问题的任何建议?
private void attendanceView(){
try{
String query ="SELECT e.ID,e.firstName,e.lastName,e.position,a.dateAttended,a.Present FROM employees e INNER JOIN attendance a ON e.ID=a.empID";
Object[][] result = connectToDB(query);
attendanceTable.setModel(new javax.swing.table.DefaultTableModel(
result, new String [] {"Employee ID","First Name","Last Name", "Position", "Date", "Present"}
)
{
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false, false, true
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
}catch (ClassNotFoundException ex) {
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
答案 0 :(得分:0)
从此,在评论中,
SELECT e.ID,e.firstName,e.lastName,e.position,a.dateAttended
FROM employees e INNER JOIN Attendance a ON a.empID =e.ID
WHERE a.dateAttended = (month of the system date)
在ms访问日期函数上进行谷歌搜索,我将now()返回当前日期和时间,而month()返回月份编号。这意味着你可以这样做:
SELECT e.ID,e.firstName,e.lastName,e.position,a.dateAttended
FROM employees e INNER JOIN Attendance a ON a.empID =e.ID
WHERE month(a.dateAttended) = month(now())
但是,有更好的方法可以做到这一点。使用where子句中的函数会减慢生产速度。此外,这只适用于当月。我建议你使用你的java代码生成两个日期变量。第一个是您要搜索的月份的第一天,另一个是下个月的第一天。然后你的where子句就是这个
where a.dateAttended >= the first variable
and a.datAttended < the other variable
如果访问支持那些,则使用查询参数可以进一步提高它。我没有使用它所以我不知道。