1

按下搜索按钮时出现以下错误:

发生错误:

异常 [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException 内部异常: java.sql.SQLException: Missing IN or OUT parameter at index:: 1 错误代码: 17041 调用: SELECT * FROM CRM_DAILY_SHEET WHERE to_char(reported_on,'dd-MM-yy') = :reportedOn 查询: ReadAllQuery(referenceClass=CrmDailySheet sql="SELECT * FROM CRM_DAILY_SHEET WHERE to_char(reported_on,'dd-MM-yy' ) = :reportedOn")

代码:

public List < CrmDailySheet > searchres() throws Exception {
    SimpleDateFormat ddMMMyyFormat = new SimpleDateFormat("dd/MM/yy");
    Date d1 = searchsht.getReportedOn();
    String date_to_string = ddMMMyyFormat.format(d1);
    return crmsrvc.searchDailysht(date_to_string);
}

try {
    Query query = em.createNativeQuery("SELECT * FROM CRM_DAILY_SHEET  
 WHERE   to_char  (reported_on,'dd-MM-yy')    =      :reportedOn", CrmDailySheet.class);
    query.setParameter("reportedOn", reportedOn);
    List < CrmDailySheet > res = query.getResultList();
    return res;
} finally {
    em.close();
}

请问有人能找到解决办法吗?

4

1 回答 1

2

您正在尝试将 JPQL 参数语法(“ :reportedOn”)与本机查询一起使用。尝试?改用并按位置设置参数值,例如:

Query query = em.createNativeQuery("SELECT * FROM CRM_DAILY_SHEET
    WHERE to_char (reported_on,'dd-MM-yy') = ?", CrmDailySheet.class);
query.setParameter(1, reportedOn);
于 2013-09-02T19:04:26.160 回答