2013-05-03 19 views
1

我收到錯誤值java.sql.SQLException:ORA-01747:無效user.table.column,TABLE.COLUMN,或列規格

java.sql.SQLException: ORA-01747: invalid user.table.column, table.column, or column specification 

我的是返回此錯誤代碼部分是這:

public boolean checkAttendance(String userid,String currentdate){ 
     boolean status=false; 
     List attendanceList=new ArrayList(); 
     Session session = getSessionFactory().openSession(); 
     try { 
      Transaction tx = session.beginTransaction(); 
      String hql = "select userid from Attendance where userid='"+ userid +"' and date='"+currentdate+"'"; 
      Query query = session.createQuery(hql); 
      attendanceList = (ArrayList) query.list(); //This Line returning the error 
      if(attendanceList.size()>0) 
      { 
       status=true; 
      } 
      tx.commit(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } finally { 
      session.close(); 
     }  

     return status; 
    } 

我試圖使SQL視圖在我的context.xml文件

<property name="hibernateProperties"> 
      <value> 
       hibernate.dialect=org.hibernate.dialect.Oracle10gDialect 
       hibernate.show_sql=true; 
      </value> 
     </property> 

我不能看到SQL得到執行的d我不知道爲什麼會出現這個錯誤,因爲我的表和字段是正確的。請幫忙。我正在使用Oracle 11g

回答

2

select userid from Attendance where userid...是SQL且無效的HQL。

您應將其更改爲類似

select a.userid from Attendance a where a.userid = :userid and a.date=:currentdate

OT - 這是一個好主意,始終使用查詢參數,而不是字符串連接。使用參數更安全,更高效。請參閱this article以獲得很好的解釋。

編輯:提前檢查查詢字符串的有效性。如果它無效,則不會發生SQL創建。如果沒有創建SQL,則無需執行任何操作。因此show_sql標誌對無效查詢不起作用。

+0

好的,謝謝我會試試這個。任何理想爲什麼我看不到我的命令gettng被執行? – ErrorNotFoundException 2013-05-03 14:44:37

+0

@Stanley我可能沒有讓自己清楚,或者我誤解了你 - 查詢字符串是無效的 - 這就是爲什麼它不被執行 – kostja 2013-05-03 14:47:13

+0

這很好,先生,但我應該能夠看到應用程序試圖查詢的查詢執行以獲取該錯誤,因爲我設置了我的'hibernate.show_sql = true;'對嗎? – ErrorNotFoundException 2013-05-03 14:59:26

相關問題