Skip to content
Advertisement

JDBC4 syntax error, but MySQL accepts the query

I’ve tried running the following query with JDBC4, which leads to a syntax error:

JavaScript

Strangely enough, when I run the query via mysql (on the same database server), the query is accepted and run.

The error message is even more confusing, as there is no closing ) on line 1.

JavaScript

The server is running MySQL 5.1.

Advertisement

Answer

JDBC accepts parameters on very specific locations only. Usually in place of scalar values. You can’t use parameters for structural items such as columns, tables, or SQL clauses.

If you are in need of this, then you should consider Dynamic SQL or proper SQL Injection.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement