SQLSyntaxErrorException when using LIKE with ojdbc7.jar
Asked Answered
M

2

5

I have the following statement :

 PreparedStatement prpStat = conn
                    .prepareStatement("SELECT * FROM natperson WHERE name LIKE ?");
            prpStat.setString(1, "A");
            ParameterMetaData pmd = prpStat.getParameterMetaData();
            ResultSet rs = prpStat.executeQuery();

and i get the following excepting when i execute the the prpStat.getParameterMetaData(); method with ojdbc7.jar. The exception is not thrown when using ojdbc6.

java.sql.SQLSyntaxErrorException: ORA-00904: "NAMEIKE": ungültiger Bezeichner

    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:392)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:385)
    at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:938)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:655)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:249)
    at oracle.jdbc.driver.T4C8Odscrarr.doODNY(T4C8Odscrarr.java:96)
    at oracle.jdbc.driver.T4CPreparedStatement.doDescribe(T4CPreparedStatement.java:719)
    at oracle.jdbc.driver.OracleStatement.describe(OracleStatement.java:4223)
    at oracle.jdbc.driver.OracleResultSetMetaData.<init>(OracleResultSetMetaData.java:52)
    at oracle.jdbc.driver.OracleStatement.getResultSetMetaData(OracleStatement.java:4206)
    at oracle.jdbc.driver.OraclePreparedStatement.getMetaData(OraclePreparedStatement.java:4603)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.getMetaData(OraclePreparedStatementWrapper.java:1510)
    at oracle.jdbc.driver.OracleParameterMetaData.getParameterMetaData(OracleParameterMetaData.java:70)
    at oracle.jdbc.driver.OraclePreparedStatement.getParameterMetaData(OraclePreparedStatement.java:11621)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.getParameterMetaData(OraclePreparedStatementWrapper.java:1552)
    at com.agfa.jdbc.test.JDBCTester.main(JDBCTester.java:45)

Any ideas how to solve this?

Monody answered 25/3, 2014 at 8:51 Comment(2)
ORA-00904 is invalid identifier. It's saying it doesn't recognize NAMEIKE that I don't see in your queryOhg
i know..the problem is that it ignores/deletes the 2 chars after the name "name" when the prpStat.getParameterMetaData(); is called.Monody
Y
6

An Oracle Bug addresses the issue where the LIKE operator causes a problem in the parser:
Bug 18590786

This bug was also referenced in a similar Oracle Bug:
Bug 18644587 : ORACLEPARAMETERMETADATAPARSER GENERATES BAD STATEMENT FOR A UNION

It is not clear whether the fix is generally available yet.

Yonit answered 21/8, 2014 at 16:32 Comment(1)
The bug appears to be fixed in the Oracle Database 12c Release 2 (12.2.0.1) JDBC driver and also isn't present in any of the Oracle Database 11g JDBC drivers. Only versions 12.1.0.1 and 12.1.0.2 seem to be affected.Dissolute
G
1

Maybe a little too late, but a workaround to this is to qualify the field before the LIKE with double quotes like below:

SELECT * FROM natperson WHERE "NAME" LIKE ?
Gaff answered 17/8, 2015 at 8:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.