Results 1 to 6 of 6

Thread: New bug in the spring jdbc

  1. #1

    Default New bug in the spring jdbc

    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

  2. #2
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    No, it is not a bug in either Spring or JDBC. This is a limitation of JDBC. You can't pass in a variable list of values using a placeholder. It is just not supported.

    You will have to either add it to the sql string, like you did, or use a stored procedure where you can pass in an array.
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  3. #3

    Default list of values

    But, this one works:

    String in_clause = "'120','121'";

    String sqlString = "SELECT " + "EMPNO," + "ENAME," + "JOB," + "MGR,"
    + "to_char(HIREDATE, 'MM/DD/YYYY') HIREDATE," + "SAL," + "COMM,"
    + "DEPTNO " + "FROM EMP "
    + "WHERE ENAME not in (?) "
    + "ORDER BY 2";

    Henry

    ----------------------------------------------------------------------------------

    Quote Originally Posted by trisberg
    No, it is not a bug in either Spring or JDBC. This is a limitation of JDBC. You can't pass in a variable list of values using a placeholder. It is just not supported.

    You will have to either add it to the sql string, like you did, or use a stored procedure where you can pa?ss in an array.

  4. #4

    Default new bug in the spring jdbc?

    But, this one works:

    String in_clause = "'120','121'";

    String sqlString = "SELECT " + "EMPNO," + "ENAME," + "JOB," + "MGR,"
    + "to_char(HIREDATE, 'MM/DD/YYYY') HIREDATE," + "SAL," + "COMM,"
    + "DEPTNO " + "FROM EMP "
    + "WHERE ENAME not in (?) "
    + "ORDER BY 2";

    and this one doesn't:

    String in_clause = "120,121";

    String sqlString = "SELECT " + "EMPNO," + "ENAME," + "JOB," + "MGR,"
    + "to_char(HIREDATE, 'MM/DD/YYYY') HIREDATE," + "SAL," + "COMM,"
    + "DEPTNO " + "FROM EMP "
    + "WHERE ENAME not in (?) "
    + "ORDER BY 2";

    Henry

  5. #5
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    Henry,

    You might find certain combinations that provide a workaround with a specific jdbc driver. However, it is still not the right way to do it
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  6. #6
    Join Date
    Aug 2004
    Location
    Vosselaar, Belgium
    Posts
    4

    Default

    Henry,

    I've moved this topic to the Data Access forum, here.

    Best regards,
    Tom.
    Last edited by Rod Johnson; Jan 18th, 2006 at 10:41 AM.

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Spring JDBC for unit tests?
    By amkush in forum Data
    Replies: 7
    Last Post: Aug 20th, 2008, 02:29 PM
  3. JDBC MetaData Through Spring?
    By gaffonso in forum Data
    Replies: 9
    Last Post: Feb 7th, 2006, 06:41 PM
  4. Replies: 2
    Last Post: Jul 19th, 2005, 07:30 AM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •