Tuesday 7 May 2019

JDBC error caused by the execution order of WHERE and SELECT clauses

The following SQL statement is executed without any issue in MySQL Workbench environment.
However, if you try to execute the same statement in Java You will encounter this error
Unknown column 'u_issubmitted' in 'where clause'
The reason is that the WHERE clause is executed before the execution of the SELECT clause, thus the attribute 'u_issubmitted' of the users table is unseen from the WHERE clause at the time of its execution. The error does not appear in the MySQL Workbench, probably because this SQL IDE has some background considerations that keep track of the attributes of every table.
The correct and safe way to do that in Java is as following with the explicit pointers to the columns (attributes) from the users table.

No comments:

Post a Comment