下面我有此查詢。我已經檢查了它在MS訪問和它工作正常。但是,當我將它添加到我的程序中時,出現「FROM子句中的語法錯誤」。出現。有關如何解決這個問題的任何建議?錯誤的「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。 jtable能夠插入數據透視查詢嗎?
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();
}
}
@Reimeus:是不是'\ n'也被認爲是一個空間? –
爲了方便閱讀我的代碼,我在查詢字符串中添加了一個新行。我會嘗試你的建議。 – rocky
我不知道MS-訪問,但也許它需要Windows換行符('\ r \ N')? Java將'\ n'作爲LF字符專用;它永遠不會將其擴展到操作系統的換行符的概念。 – yshavit