Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringJDBC Gives ORA-00933: SQL command not properly ended But Query Runs OK in DB Client

The following Oracle query runs OK in my DB Client, PL/SQL Developer, and returns 1 result.

On running it via NamedParameterJdbcTemplate (SpringJDBC) in my Java app, I get

java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

There can't be any space issues or anything obvious, because this exact query completes in 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);       
}   
like image 331
gene b. Avatar asked Oct 15 '25 14:10

gene b.


1 Answers

I think you don't require the semi colon with the sql string.

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 ";
like image 72
Rohit Avatar answered Oct 18 '25 06:10

Rohit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!