pgjdbc: Receiving "ERROR: prepared statement \"S_2\" does not exist"

In my application I am receiving many errors regarding prepared statements not existing.

The libraries that I am using are:

  • org.postgresql/postgresql “9.4.1208”
  • hikari-cp “1.7.1” (Clojure wrapper for com.zaxxer. HikariCP)
  • And org.clojure/java.jdbc “0.6.1”

Posgres is version 9.3.11.

The operations I am performing are not very complicated. Essentially:

(with-db-connection [conn datasource]
    (let [result (j/query conn ["SELECT thing from table where column =  ?" value])]
      ;; do stuff with result
))

with-db-connection is a clojure jdbc macro that will call close on the connection at the completion of the block. The connection comes from the hikari-cp datasource so that will return the connection to the connection pool.

The actual stacktrace: “class org.postgresql.util.PSQLException: ERROR: prepared statement "S_2" does not exist” “org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2284)”, “org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2003)”, “org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)”, “org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)”, “org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)”, “org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114)”, “com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)”, “com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)”, “clojure.java.jdbc$db_query_with_resultset$run_query_with_params__10416.invoke(jdbc.clj:831)”, “clojure.java.jdbc$db_query_with_resultset.invoke(jdbc.clj:847)”, “clojure.java.jdbc$query.invoke(jdbc.clj:874)”, “clojure.java.jdbc$query.invoke(jdbc.clj:867)”,

I’ve spent some time googling this stacktrace without much luck. I was hoping that someone here might have an idea of what is going on.

Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 21 (12 by maintainers)

Most upvoted comments

Named prepared statements are created after you use a statement 5 times on the same connection and save time and round trips. Setting preparedStatement=0 is the correct solution. you just won’t get the advantage of named statements