简体   繁体   English

java.sql.SQLException:ORA-01747:无效的user.table.column,table.column或列规范

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

I am getting the error 我收到错误

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

My Piece of code that is returning this error is this: 返回此错误的我的代码段是这样的:

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;
    }

I have tried to enable view sql in my Context.xml file 我试图在Context.xml文件中启用视图SQL

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

I cannot see the sql getting executed and I do not Know why this error is coming because my table and Fields are correct. 我看不到sql正在执行,而且我不知道为什么会出现此错误,因为我的表和字段正确。 Please Help. 请帮忙。 Am using Oracle 11g 我正在使用Oracle 11g

select userid from Attendance where userid... is SQL and not valid HQL. select userid from Attendance where userid...是SQL且不是有效的HQL。

You should change it to something like 您应该将其更改为

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

OT - it is a good idea to always use query parameters and not string concatenation. OT-始终使用查询参数而不是字符串连接是一个好主意。 Using parameters is safer and more efficient. 使用参数更安全,更有效。 See this article for a good explanation. 请参阅本文以获得良好的解释。

EDIT: the validity of the query string is checked early. 编辑:查询字符串的有效性是早期检查。 If it is invalid, no SQL creation takes place. 如果无效,则不会创建任何SQL。 If no SQL is created, there is nothing to execute. 如果未创建SQL,则没有任何执行。 The show_sql flag therefore has no effect for invalid queries. 因此, show_sql标志对无效查询无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM