String in_clause = "(120,'JOHN'),(121,'SMITH')";
String sqlString = "SELECT " + "EMPNO," + "ENAME," + "JOB," + "MGR,"
+ "to_char(HIREDATE, 'MM/DD/YYYY') HIREDATE," + "SAL," + "COMM,"
+ "DEPTNO " + "FROM EMP "
+ "WHERE (empno,ename) not in (?) "
+ "ORDER BY 2";
errors:
08:08:26,233 WARN - [support.SQLErrorCodeSQLExceptionTranslator.transla te] Unab
le to translate SQLException with errorCode '920', will now try the fallback tra
nslator
08:08:26,233 INFO - [support.SQLStateSQLExceptionTranslator.translate] Translat
ing SQLException with SQLState '42000' and errorCode '920' and message [ORA-0092
0: invalid relational operator
]; SQL was [SELECT EMPNO,ENAME,JOB,MGR,to_char(HIREDATE, 'MM/DD/YYYY') HIREDATE,
SAL,COMM,DEPTNO FROM EMP WHERE (empno,ename) not in (?) ORDER BY 2] for task [exe
cuting PreparedStatementCallback [org.springframework.jdbc.core.JdbcTemplate$Sim
plePreparedStatementCreator@25b72a]]
08:08:26,233 INFO - [interceptor.TransactionInterceptor.onThrowable] Invoking r
ollback for transaction on method 'dispEmp' in class [edu.umich.umms.springemp.s
ervice.EmpService] due to throwable [org.springframework.jdbc.BadSqlGrammarExcep
tion: Bad SQL grammar [SELECT EMPNO,ENAME,JOB,MGR,to_char(HIREDATE, 'MM/DD/YYYY'
) HIREDATE,SAL,COMM,DEPTNO FROM EMP WHERE (empno,ename) not in (?) ORDER BY 2] in
task 'executing PreparedStatementCallback [org.springframework.jdbc.core.JdbcTe
mplate$SimplePreparedStatementCreator@25b72a]'; nested exception is java.sql.SQL
Exception: ORA-00920: invalid relational operator
]
08:08:26,233 INFO - [datasource.DataSourceTransactionManager.rollback] Initiati
ng transaction rollback
org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [SELECT EMPNO,E
NAME,JOB,MGR,to_char(HIREDATE, 'MM/DD/YYYY') HIREDATE,SAL,COMM,DEPTNO FROM EMP W
HERE (empno,ename) not in (?) ORDER BY 2] in task 'executing PreparedStatementCal
lback [org.springframework.jdbc.core.JdbcTemplate$SimpleP reparedStatementCreator
@25b72a]'; nested exception is java.sql.SQLException: ORA-00920: invalid relatio
nal operator
----------------------------------------------------------------------------
But, If i change the sql to the following, it works.
String in_clause = "(120,'JOHN'),(121,'SMITH')";
String sqlString = "SELECT " + "EMPNO," + "ENAME," + "JOB," + "MGR,"
+ "to_char(HIREDATE, 'MM/DD/YYYY') HIREDATE," + "SAL," + "COMM,"
+ "DEPTNO " + "FROM EMP "
+ "WHERE (empno,ename) not in ("+in_clause+") "
+ "ORDER BY 2";
Is this a bug in the spring jdbc?
-Henry


Reply With Quote
