gpt4 book ai didi

java - 错误 : org. hibernate.exception.SQLGrammarException: 无法提取 ResultSet 并且 dateAccessed 是未知列

转载 作者:行者123 更新时间:2023-11-30 22:07:03 25 4
gpt4 key购买 nike

我在 spring MVC JAVA 中执行下面的查询

if (currentFireTime != null && previousFireTime != null) {
timePart = " sal.dateAccessed between '" + previousFireTime + "' and '" + currentFireTime + "' and ";
}
String queryString = " select count(*) as COUNT FROM LogData sal where " + timePart + " sal.userSigned = false and sal.batchMetaDataId = "+batchId;
SQLQuery sq =sessionFactory.getCurrentSession().createSQLQuery(queryString);
sq.addScalar("COUNT", IntegerType.INSTANCE);
sq.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
List<Map<String,Object>> resultSet=sq.list();
return (Integer)resultSet.get(0).get("COUNT");

当执行时看起来像这样并将其放入 Mysql 中它工作正常。但是我得到如下所示的错误。

select count(*) as COUNT FROM LogData sal where sal.dateAccessed between '2016-12-26 00:00:00.618' and '2016-12-26 01:00:00.618' and  sal.userSigned = false and sal.batchMetaDataId = 86

显示错误

    org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)

我需要更改显示的代码中的哪些内容?

最佳答案

您获取计数的方式有误。试试这个:

resultSet.getInt("COUNT");

关于java - 错误 : org. hibernate.exception.SQLGrammarException: 无法提取 ResultSet 并且 dateAccessed 是未知列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41330031/

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