1

I have the following SQL statement:

SELECT ID_TABLE_1
FROM TABLE_1
WHERE TABLE_1.STRING_FIELD=(
   SELECT ANOTHER_STRING FROM ANOTHER_TABLE      
   WHERE ID_ANOTHER_TABLE = 1) 
AND TABLE_1.FIELD_2= :PARAM

When I prepare the statement, everything is fine. But when I call getParameterMetaData(), an exception occurs:

Caused by: java.sql.SQLSyntaxErrorException: ORA-00923: FROM keyword not found where expected

private static Pair<JDBCResources, Integer> execSQL(Connection conn,   String sqlStatement, String params, boolean executeUpdate) {
  try {
    PreparedStatement ps = conn.prepareStatement(sqlStatement); //OK
    ParameterMetaData paramData = ps.getParameterMetaData(); //java.sql.SQLSyntaxErrorException

The exception comes if I use Oracle Database 12.1.0.2 JDBC Driver -> ojdbc7.jar (3,698,857 bytes) It worked with the Java 6 JDBC driver -> ojdbc6.jar (1,988,051 bytes)

What's wrong in this SQL statement? Since I'm using Java 8, can I use the ojdbc7 driver even on Oracle Database X / XI?

David Obber
  • 131
  • 2
  • 10
  • 1
    You can use the ojdbc7 driver even if you're using Java 8. The 7 in ojdbc7 just means it was compiled and build using Java 7. Same with ojdbc6.jar, it was compiled and built with Java 6. Have you tried using an ojdbc8 jar? – Brandon G Oct 11 '18 at 16:47
  • [This](https://stackoverflow.com/questions/22629438/sqlsyntaxerrorexception-when-using-like-with-ojdbc7-jar) might be related. – Andrew S Oct 11 '18 at 16:54
  • Parameters need to be denoted by `?` in plain JDBC, not as `:param` –  Oct 11 '18 at 19:16
  • @Brandon G Using ojdbc8 worked! thank you! – David Obber Oct 12 '18 at 07:20
  • @a_horse_with_no_name - You're right, but replacing the param name with a '?' doesn't change the issue. I'm using a NamedParameterStatement class that replaces param names with '?' – David Obber Oct 12 '18 at 07:22
  • The line `PreparedStatement ps = conn.prepareStatement(sqlStatement);` will **not** accept `:param` as a valid placeholder - if that is not the code you are using, then please add the real code you use. –  Oct 12 '18 at 07:51
  • 1
    The code I posted works perfecty with thousands of query with named params and prepareStatement accepts :param (tested with ojdbc6 and ojdbc8) – David Obber Oct 24 '18 at 06:32

0 Answers0