SpringJDBC提供ORA-00933:SQL命令未正确终止,但查询在DB Client中运行正常

gen*_* b. 2 spring spring-jdbc jdbctemplate

以下Oracle查询在我的数据库客户端PL / SQL Developer中运行正常,并返回1个结果。

在我的Java应用程序中通过NamedParameterJdbcTemplate(SpringJDBC)运行它时,我得到

java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
Run Code Online (Sandbox Code Playgroud)

不能有任何空间问题或任何明显的问题,因为此确切的查询已在PL / SQL中完成。

private static final String SELECT1 = 
        " SELECT COUNT(*) " 
        " FROM table1 t1, table2 t2 " + 
        " WHERE t1.received_date > TRUNC(sysdate - 1) " + 
        " AND t1.received_date < TRUNC(sysdate) " + 
        " AND t1.type IN ('TYPE1', 'TYPE2') " + 
        " AND t2.received_num = t1.received_num; ";

public int getSelect1() {

    HashMap<String,Object> paramMap = new HashMap<String,Object>();     
    return jdbcTemplate.queryForObject(SELECT1, paramMap, Integer.class);       
}   
Run Code Online (Sandbox Code Playgroud)

Roh*_*hit 5

我认为您不需要使用带有SQL字符串的分号。

private static final String SELECT1 = 
        " SELECT COUNT(*) " +
        " FROM table1 t1, table2 t2 " + 
        " WHERE t1.received_date > TRUNC(sysdate - 1) " + 
        " AND t1.received_date < TRUNC(sysdate) " + 
        " AND t1.type IN ('TYPE1', 'TYPE2') " + 
        " AND t2.received_num = t1.received_num ";
Run Code Online (Sandbox Code Playgroud)