Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

PreparedStatement fails to execute  RSS feed

 
olze oli
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i created a prepared statement with a simple select, but it wont be executed:



The error message is:
org.postgresql.util.PSQLException: FEHLER: Syntaxfehler am Ende der Eingabe
Position: 52
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)


I have no idea whats wrong with that query. Can please someone explain me what the problem is?

Syntaxfehler am Ende der Eingabe means: Syntax Error at the end of the input.
 
Ed Ward
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did "stmt" come from?
You sure you do not want to do prepStmt.executeQuery() since you went through the trouble of prepping it?
stmt.executeQuery(sql) in your code is attempting to execute the raw SQL statement, with the ? which has not yet been set.

Least, looks that way to me.
 
olze oli
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have been right... thanks
I had a normal Statement (stmt) and a PreparedStatement (prepStmt).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!