SQL exception preparing query with ORMLite

后端 未结 4 447
一向
一向 2021-01-15 05:58

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

4条回答
  •  没有蜡笔的小新
    2021-01-15 06:42

    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);
    

提交回复
热议问题