JDBC returning MySQLSyntaxError Exception with correct statement

Solution 1:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? , ? , DEFAULT , NULL )' at line 1

Those placeholders ? should not appear in the MySQL side at all.

Look here,

sInserim.executeUpdate(sqlCommandInserim);

you're passing the raw SQL string into executeUpdate() instead of executing the PreparedStatement with the set values.

Replace it by

sInserim.executeUpdate();

The executeUpdate(sqlString) should be used on Statement only.


Unrelated to the concrete problem, you should be closing the PreparedStatement in the finally block to prevent resource leaking in case of exceptions. The same applies to Connection, Statement and ResultSet by the way.