我在下面有这个查询。我已经在ms访问中检查了它,它运行正常。但是当我将它添加到我的程序中时,A" FROM子句中的语法错误。"出现。有关如何解决此问题的任何建议吗?
String query ="TRANSFORM COUNT(a.present)\n" +
"SELECT e.ID,e.firstName,e.lastName,e.position,e.rate\n" +
"FROM employees e \n" +
"INNER JOIN attendance a \n" +
"ON e.ID = a.empID \n" +
"GROUP BY e.ID,e.firstName,e.lastName,e.position,e.rate \n" +
"PIVOT a.dateAttended";
这是查询所属的完整方法。 connectToDB方法用于将结果集插入jtable。 jtables是否能够插入数据透视查询?
private void attendanceView() throws ClassNotFoundException{
try{
String query ="TRANSFORM COUNT(a.present) " +
"SELECT e.ID,e.firstName,e.lastName,e.position,e.rate " +
"FROM employees e " +
"INNER JOIN attendance a " +
"ON e.ID = a.empID " +
"GROUP BY e.ID,e.firstName,e.lastName,e.position,e.rate " +
"PIVOT a.dateAttended";
Object[][] result = connectToDB(query);
System.out.print(result);
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];
}
});
}catch (ClassNotFoundException ex) {
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
}
}
答案 0 :(得分:-1)
试试这个:
将同一个查询分成多行时,空格很重要。
String query ="TRANSFORM COUNT(a.present) " +
"SELECT e.ID,e.firstName,e.lastName,e.position,e.rate " +
"FROM employees e " +
"INNER JOIN attendance a " +
"ON e.ID = a.empID " +
"GROUP BY e.ID,e.firstName,e.lastName,e.position,e.rate " +
"PIVOT a.dateAttended";