Home > database >  error in SQL syntax; check manual corresponds to your MariaDB server version for the right syntax to
error in SQL syntax; check manual corresponds to your MariaDB server version for the right syntax to

Time:09-05

Error In Connection Due Tocom.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Div='aa' WHERE Roll_No=2' at line 1

enter image description here

CodePudding user response:

Div is a reserved word, it should be quoted.

Using double quotes, note that they must be escaped because they are inside a Java String which is delimited by doubles quotes:

"UPDATE Student SET Name=?,Std=?,\"Div\"=? WHERE Roll_No=?";

Or using backticks:

"UPDATE Student SET Name=?,Std=?,`Div`=? WHERE Roll_No=?";

See the list of reserved words at https://mariadb.com/kb/en/reserved-words/

As you're a student, let me give you a friendly advice: it's a good practice to give full names to your columns rather than abbreviations (e.g. Division rather than Div), this will improve readability and decreases the probability to run into reserved words.

  • Related