I am using an ORM (ORMlite) and all my calls are going well until I get the following error.
Exception in thread \"main\" org.h2.jdbc.JdbcSQLExceptio
Syntax error in SQL statement " SELECT * FROM ""STORIES"" WHERE ""TITLE""...
@bemace is correct that there seem to be quotes in the title that is screwing up the escaping of strings generated by the query.
In ORMLite, you should use the SelectArg
feature which will generate a query with SQL ? arguments and then pass the string to the prepared statement directly.
For documentation on the SelectArg
, see:
http://ormlite.com/docs/select-arg
With SelectArg
, you'd do something like:
QueryBuilder queryBuilder = StoryDao.queryBuilder();
SelectArg titleArg = new SelectArg();
queryBuilder.where().eq(Story.TITLE_FIELD_NAME, titleArg);
PreparedQuery preparedQuery = queryBuilder.prepare();
titleArg.setValue(title);
List accountList = StoryDao.query(preparedQuery);