您好,我正在使用JDBC查询,但出现此错误,但是我不明白为什么,或者该错误的确切含义以及查询的错误所在。 查询如下
private List<StatisticsLog> runStatistics(Integer partnerId, LocalDate ldStart, LocalDateTime ldtEnd, String statType)
{
return jdbcTemplate.query("SELECT S.APP_ID, S.LOG_TYPE, ACC.CONTACT_PERSON_FIRST_NAME, ACC.CONTACT_PERSON_LAST_NAME, ACV.VERSION_APP_NAME, "
+ "'" + statType.trim() + "' STATTYPE, "
+ "ACV.APP_CATALOG_ID, ACV.APP_CATALOG_VERSION_ID, ACV.VERSION, ACV.UPDATED_AT, ACV.VERSION_LOGO_EXT, ACV.HAS_LOGO, "
+ "LANG.LANGUAGE_NAME_SHORT, LANG.LANGUAGE_ID , S.count, S.PARTNER_ID, APP.CREATED_AT "
+ "FROM (SELECT partner_id, log_type, app_id, language_id, count(*) as count FROM public.statistics_log "
+ " WHERE partner_id = ? "
+ " and logged_at between ? and ? "
+ "group by 1, log_type, app_id, language_id) as S "
+ "INNER JOIN APP_CATALOG_ACCOUNT ACP ON ACP.APP_CATALOG_SERIAL_ID = S.APP_ID "
+ "INNER JOIN APP_CATALOG APP ON APP.APP_CATALOG_SERIAL_ID = S.APP_ID "
+ "INNER JOIN ACCOUNT ACC ON ACC.ACCOUNT_ID = S.PARTNER_ID "
+ "INNER JOIN APP_CATALOG_VERSION ACV on ACV.APP_CATALOG_SERIAL_ID = APP.APP_CATALOG_SERIAL_ID AND ACV.STATUS = 3 "
+ "INNER JOIN LANGUAGE LANG ON LANG.LANGUAGE_ID = ACV.LANGUAGE_ID "
+ "ORDER BY S.count desc ",
new Object[] { partnerId, ldStart, ldtEnd }, new StatisticsLogRowMapper());
}
我从属于应用程序目录的CREATED_AT
列中得到了错误,我认为应该在该列中,此外,为了更加详细,我还将附加StatisticsLogRowMapper
public class StatisticsLogRowMapper implements RowMapper<StatisticsLog>
{
@Override
public StatisticsLog mapRow(ResultSet rs, int rowNum) throws SQLException
{
StatisticsLog stat = new StatisticsLog();
stat.setAppId(rs.getInt("APP_ID"));
stat.setPartnerId(rs.getInt("PARTNER_ID"));
stat.setCount(rs.getLong("COUNT"));
stat.setCreatedAt(rs.getTimestamp("CREATED_AT").toLocalDateTime());
stat.setPartnerFirstName(rs.getString("CONTACT_PERSON_FIRST_NAME"));
stat.setPartnerLastName(rs.getString("CONTACT_PERSON_LAST_NAME"));
stat.setAppNameDefault(rs.getString("VERSION_APP_NAME"));
stat.setAppCatalogId(rs.getInt("APP_CATALOG_ID"));
stat.setStatType(rs.getString("STATTYPE"));
stat.setLogType(LogTypeEnum.valueOf(rs.getString("LOG_TYPE").trim()));
stat.setAppCatalogVersionId(rs.getInt("APP_CATALOG_VERSION_ID"));
stat.setVersion(rs.getInt("VERSION"));
stat.setUpdatedAt(rs.getDate("UPDATED_AT"));
stat.setVersionLogoExt(rs.getString("VERSION_LOGO_EXT"));
stat.setHasLogo(rs.getBoolean("HAS_LOGO"));
stat.setLanguageNameShort(rs.getString("LANGUAGE_NAME_SHORT"));
stat.setLanguageId(rs.getInt("LANGUAGE_ID"));
return stat;
}
}
错误是:“ PreparedStatementCallback;错误的SQL语法[SELECT S.APP_ID,S.LOG_TYPE,ACC.CONTACT_PERSON_FIRST_NAME,ACC.CONTACT_PERSON_LAST_NAME,ACV.VERSION_APP_NAME,“ days30” STATTYPE,ACV.APP_CATALOG_ID,ACV.APP_CATALOG_ID, VERSION,ACV.UPDATED_AT,ACV.VERSION_LOGO_EXT,ACV.HAS_LOGO,LANG.LANGUAGE_NAME_SHORT,S.count,S.PARTNER_ID FROM(选择partner_id,log_type,app_id,language_id,count(*)作为来自public.statistics_log的计数,在?和?按1,log_type,app_id,language_id,partner_id分组),如S INNER JOIN APP_CATALOG_ACCOUNT ACP在ACP.APP_CATALOG_SERIAL_ID = S.APP_ID INNER JOIN APP_CATALOG APP在APP.APP_CATALOG_SERIAL_ID = S.APP_ID INNER JOIN帐户ACC上.PARTNER_ID内联接AC_上的APP_CATALOG_VERSION ACV.APP_CATALOG_SERIAL_ID = APP.APP_CATALOG_SERIAL_ID和ACV.STATUS = 3内联接语言LANG.LANGUAGE_ID = ACV.LANGUAGE_ID ORDER BY S.count descorg];嵌套异常是SQL。 :在此ResultSet中找不到列名CREATED_AT。”
在错误字段中没有该字段
如果您有任何疑问或可能尝试解决的问题,请不要犹豫,我将不胜感激,即使是最小的帮助也要感谢您。
答案 0 :(得分:1)
我看到查询的第二行有一个错误-+“'” + statType.trim()+“'STATTYPE,”,在引号之后。 STATTYPE没有表引用,并附加有字符串。那可能是另一个问题。我没有足够的声誉,所以无法对这个问题发表评论。