org.postgresql.util.PSQLException: ERROR: syntax error at or near "`"

5,702 views
Skip to first unread message

Stodge

unread,
Sep 18, 2012, 8:42:24 AM9/18/12
to ormlit...@googlegroups.com
I'm getting an error that I don't understand while trying to create a custom data persister.

2012-09-18 08:37:00,526 DEBUG ( ?:?) - created dao for class class Region with reflection
2012-09-18 08:37:00,533 DEBUG ( ?:?) - built statement SELECT * FROM `region` WHERE `label` = 'Fred' 
2012-09-18 08:37:00,579 DEBUG ( ?:?) - opened connection to jdbc:postgresql://127.0.0.1/mydb got #1355906755
2012-09-18 08:37:00,587 DEBUG ( ?:?) - prepared statement 'SELECT * FROM `region` WHERE `label` = 'Fred' ' with 0 args
2012-09-18 08:37:00,594 DEBUG ( ?:?) - cache released connection #221607586

org.postgresql.util.PSQLException: ERROR: syntax error at or near "`"
Position: 15
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
at com.j256.ormlite.jdbc.JdbcCompiledStatement.runQuery(JdbcCompiledStatement.java:55)
at com.j256.ormlite.stmt.SelectIterator.<init>(SelectIterator.java:55)
at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java:206)
at com.j256.ormlite.stmt.StatementExecutor.query(StatementExecutor.java:155)
at com.j256.ormlite.dao.BaseDaoImpl.query(BaseDaoImpl.java:261)
at TestORMLite.main(TestORMLite.java:48)

I found one post that mentioned something similar but the fix didn't seem relevant. Any suggestions appreciated.

Thanks

Stodge

unread,
Sep 18, 2012, 8:47:04 AM9/18/12
to ormlit...@googlegroups.com
I also tried using:

SelectArg selectArg = new SelectArg();
QueryBuilder<Region, Integer> queryBuilder =
dao.queryBuilder();
queryBuilder.where().eq("label", selectArg);
selectArg.setValue("fred");

But I still get the same exception.

Gray Watson

unread,
Sep 19, 2012, 2:21:25 PM9/19/12
to ormlit...@googlegroups.com

On Sep 18, 2012, at 8:42 AM, Stodge wrote:

> I'm getting an error that I don't understand while trying to create a custom data persister.
>
> 2012-09-18 08:37:00,526 DEBUG ( ?:?) - created dao for class class Region with reflection
> 2012-09-18 08:37:00,533 DEBUG ( ?:?) - built statement SELECT * FROM `region` WHERE `label` = 'Fred'
> org.postgresql.util.PSQLException: ERROR: syntax error at or near "`"

Huh. So it looks like you are not using the Postgres database type. It should have used double-quote (") to escape the "region" table name. What JDBC URL are you using? Any chance you are using "jdbc:mysql:..." instead of "jdbc:postgresql:..."?

gray

Gray Watson

unread,
Sep 19, 2012, 2:25:29 PM9/19/12
to ormlit...@googlegroups.com
On Sep 18, 2012, at 8:42 AM, Stodge wrote:

> 2012-09-18 08:37:00,579 DEBUG ( ?:?) - opened connection to jdbc:postgresql://127.0.0.1/mydb got #1355906755

Oh, sorry. Didn't see that. How are you wiring your database connection source? Something like just this:

connectionSource = new JdbcConnectionSource(DATABASE_URL);

I have good test coverage on this and it shows that it is using " character.
gray

Reply all
Reply to author
Forward
0 new messages