gpt4 book ai didi

java.sql.SQLException : ORA-01747: invalid user. table.column、table.column 或列规范

转载 作者:行者123 更新时间:2023-11-30 04:23:50 24 4
gpt4 key购买 nike

我收到错误

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

我尝试在 Context.xml 文件中启用查看 sql

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

我看不到正在执行的 sql,并且我不知道为什么会出现此错误,因为我的表和字段是正确的。请帮忙。我正在使用 Oracle 11g

最佳答案

从考勤中选择用户 ID,其中用户 ID... 是 SQL,而不是有效的 HQL。

你应该将其更改为类似

从考勤 a 中选择 a.userid,其中 a.userid = :userid 和 a.date=:currentdate

OT - 始终使用查询参数而不是字符串连接是一个好主意。使用参数更安全、更高效。请参阅this article以获得一个很好的解释。

编辑:提前检查查询字符串的有效性。如果无效,则不会创建 SQL。如果没有创建 SQL,则不执行任何操作。因此,show_sql 标志对于无效查询没有影响。

关于java.sql.SQLException : ORA-01747: invalid user. table.column、table.column 或列规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16361372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com