SQL query processing query with ORMLite

I am using ORM (ORMlite) and all my calls go well until I get the following error.

An exception in the stream "main" org.h2.jdbc.JdbcSQLException: syntax error in the SQL statement "SELECT * FROM" "STORIES" "WHERE" "TITLE" "=" In-depth output case "NOT FOLLOWED [*] ''"; SQL statement: SELECT * FROM Stories WHERE title = "Malfunctions in cases of disconnection" '[42000-152] at org.h2.message.DbException.getJdbcSQLException (DbException.java:327) on org.h2.message. DbException.get (DbException.java:167) at org.h2.message.DbException.get (DbException.java:144) at org.h2.message.DbException.getSyntaxError (DbException.java:179) on org.h2.command .Parser.getSyntaxError (Parser.java:480) at org.h2.command.Parser.prepareCommand (Parser.java:229) at org.h2.engine.Session.prepareLocal (Session.java:426) on org.h2. engine.Session.prepareCommand (Session.javahaps74) at org.h2.jdbc.JdbcConnection.prepareCommand (JdbcConnection.java:1093) at org.h2.jdbc.JdbcPreparedStatement. (JdbcPreparedStatement.java:71) at org.h2.jdbc.JdbcConnection.prepareStatement (JdbcConnection.java:601) at com.j256.ormlite.jdbc.JdbcDatabaseConnection.compileStatement (JdbcDatabaseConnection.java.jite.j25.java.java. stmt.mapped.MappedPreparedStmt.compile (MappedPreparedStmt.java:44) at com.j256.ormlite.stmt.StatementExecutor.buildIterator (StatementExecutor.java:169) at com.j256.ormlite.stmt.StatementExecutor.query (StatementExecutor 119) on com.j256.ormlite.dao.BaseDaoImpl.query (BaseDaoImpl.java:189)

I am confused what is going wrong. I invoke a search on these lines:

 // get our query builder from the DAO QueryBuilder<Story, Integer> queryBuilder = StoryDao.queryBuilder(); // the 'title' field must be equal to title (a variable) queryBuilder.where().eq(Story.TITLE_FIELD_NAME, title); // prepare our sql statement PreparedQuery<Story> preparedQuery = queryBuilder.prepare(); // query for all stories that have that title List<Story> accountList = StoryDao.query(preparedQuery); 
+2
java sql exception h2 ormlite
source share
4 answers

Syntax error in SQL statement "SELECT * FROM" "STORIES" "WHERE" "TITLE" "...

@bemace is true that the header seems to have quotation marks that wrap the escaping of the lines generated by the request.

In ORMLite, should you use the SelectArg function, which will generate a query with SQL? arguments, and then pass the string directly to the prepared statement.

For documentation on SelectArg see

http://ormlite.com/docs/select-arg

With SelectArg you will do something like:

 QueryBuilder<Story, Integer> queryBuilder = StoryDao.queryBuilder(); SelectArg titleArg = new SelectArg(); queryBuilder.where().eq(Story.TITLE_FIELD_NAME, titleArg); PreparedQuery<Story> preparedQuery = queryBuilder.prepare(); titleArg.setValue(title); List<Story> accountList = StoryDao.query(preparedQuery); 
+10
source share

I kind of guess, but it looks like there is a problem with the value in the title field, possibly without a quotation mark?

I am not familiar with ORMLite, but title = 'Deepcut case leads 'not followed'' looks wrong. It should probably be "Deepcut case leads 'not followed'" or 'Deepcut case leads \'not followed\'' or some.

+1
source share

The correct syntax for the operator is:

 SELECT * FROM Stories WHERE title = 'Deepcut case leads' 'not followed' '';

Note the duplicated single quotes inside the string literal.

You will need to tell your ORM level to follow ANSI SQL rules for literals.

+1
source share

An exception indicates there is a syntax problem with your generated SELECT operation. Can you print the generated request? This can help you pinpoint the problem.

EDIT: By carefully looking at your footprint, it is shown that the string escaping cannot be processed here. Is this your own QueryBuilder? Also, according to this link , are you SelectArg or directly setting the header?

0
source share

All Articles