I have JDBC code which inserts into a database table by executing a PreparedStatement. When I run the code on an in-memory HSQLDB database (as part of a JUnit test) I get a
Some further info I found in http://hsqldb.org/doc/changelog_1_7_2.txt:
The execute(String sql), executeUpdate(String sql) and executeQuery(String sql)
commands are no-longer supported for PreparedStatements according to JDBC specs.
Use an ordinary Statement for calling these methods.
Systemic issues with HSQLDB are often due to mismatches in server vs. driver version (any mismatch at all will not work in my experience).
I mostly suspect this isn't your issue. Since you said the db is "in memory," I'm guessing the server & driver are the same .jar file. But in case my guess is wrong, I thought I'd throw this out there.
You need to call preparedStatement.executeUpdate()
(without the parameter sql
).
You called the method PreparedStatement.executeUpdate(String sql)
, which is illegal according to the JDBC specification. It doesn't really make sense to pass the SQL statement again, because you have already passed it when you created the PreparedStatement object. Even thought you pass the same string, it's not legal to call this method. It's a bit strange that calling a method is not legal :-) but that's the way it is. All standard conforming JDBC drivers need to throw an exception in this case.
But I agree the error message is cryptic.