When i am executing my method i am getting this message in my log file:
org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [DELETE FROM DEVICES WHERE DEVICEID IN ([3715, 3716]) ]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00936: missing expression
Can anyone help please?
public int removeDevice(ArrayList<Long> deviceId) {
StringBuffer query = new StringBuffer("DELETE FROM DEVICES ");
query.append("WHERE DEVICEID IN ("+deviceId+") ");
int rowsRemoved = 0;
try {
rowsRemoved = getSimpleJdbcTemplate().update(query.toString());
} catch(Exception e) {
log.error("query: " + query.toString());
}
return rowsRemoved;
}
Perhaps deviceId.toString()
returns [3715,3716]
.. it has to be just 3715,3716
. So change your logic to form a comma separated string
query.append("WHERE DEVICEID IN ("+ deviceId.toString().replaceAll("\\[|\\]", "") +") ");
This should help! Sorry not tested! This removes the Square brackets.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments