ejc-sql
ejc-sql copied to clipboard
Unable to execute update statement
After connecting to PostgreSQL database, I can execute select statements, but any update statement produce error:
Error: This ResultSet is closed.
My configuration:
(use-package ejc-sql
:config
(ejc-set-rows-limit nil)
(setq ejc-org-mode-show-results nil)
(add-hook 'ejc-sql-minor-mode-hook
(lambda ()
(auto-complete-mode t)
(ejc-ac-setup)))
;; Define connections
(ejc-create-connection
name
:classpath "/home/rrudakov/.m2/repository/postgresql/postgresql/9.3-1102.jdbc41/postgresql-9.3-1102.jdbc41.jar"
:subprotocol "postgresql"
:subname (format "//%s:5432/%s" "hostname" "dbname")
:user "username"
:password "password"))
Emacs version: GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.7) of 2019-03-17
Could you provide a full stack trace, please (by enabling M-x toggle-debug-on-error
)?
Also, please show your leiningen & java versions (via lein version
).
$ lein version
Leiningen 2.9.1 on Java 1.8.0_202 Java HotSpot(TM) 64-Bit Server VM
java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
toggle-debug-on-error
doesn't change anything. I got popup:
Looks like you run queries from org-mode
buffer. Ok, I can't reproduce exactly this issue, but could you please try the last version from master
.
Looks like you run queries from org-mode
I tried both, from org-mode
and from ejc-get-temp-edit-buffer
. In master I still can reproduce the issue.
p.s: Wrote from another account
Looks like, you query is considered as resulted with :result-set
. Probably, we face here with select for update
case or something like that. The actual code used to determine whether this SQL should have a result set or not is damn trivial:
https://github.com/kostafey/ejc-sql/blob/master/src/ejc_sql/connect.clj#L121
Could you check it out? The actual debug process is simple. ejc-sql
can be considered as common Clojure & Leningen & CIDER project. So, after run ejc-connect
for any sql-mode
or org-mode
buffer,
you can open connect.clj
file, then type and eval (@db
atom contains connection info of the last used database):
(in-ns 'ejc-sql.connect)
(eval-sql-core :db @db
:sql "Actual SQL query")
Looks the same.
What about direct evaluation:
(j/execute! @db (list "UPDATE profiles SET avatar='test' WHERE id=1"))
Show: Project-Only All
Hide: Clojure Java REPL Tooling Duplicates (10 frames hidden)
1. Unhandled org.postgresql.util.PSQLException
This ResultSet is closed.
AbstractJdbc2ResultSet.java: 2852 org.postgresql.jdbc2.AbstractJdbc2ResultSet/checkClosed
AbstractJdbc2ResultSet.java: 1875 org.postgresql.jdbc2.AbstractJdbc2ResultSet/setFetchSize
Jdbc4Statement.java: 37 org.postgresql.jdbc4.Jdbc4Statement/createResultSet
AbstractJdbc2Statement.java: 221 org.postgresql.jdbc2.AbstractJdbc2Statement$StatementResultHandler/handleResultRows
QueryExecutorImpl.java: 1853 org.postgresql.core.v3.QueryExecutorImpl/processResults
QueryExecutorImpl.java: 255 org.postgresql.core.v3.QueryExecutorImpl/execute
AbstractJdbc2Statement.java: 561 org.postgresql.jdbc2.AbstractJdbc2Statement/execute
AbstractJdbc2Statement.java: 405 org.postgresql.jdbc2.AbstractJdbc2Statement/executeWithFlags
AbstractJdbc2Connection.java: 382 org.postgresql.jdbc2.AbstractJdbc2Connection/execSQLUpdate
AbstractJdbc2Connection.java: 904 org.postgresql.jdbc2.AbstractJdbc2Connection/getTransactionIsolation
jdbc.clj: 790 clojure.java.jdbc/db-transaction*
jdbc.clj: 769 clojure.java.jdbc/db-transaction*
jdbc.clj: 782 clojure.java.jdbc/db-transaction*
jdbc.clj: 769 clojure.java.jdbc/db-transaction*
jdbc.clj: 1030 clojure.java.jdbc/db-do-execute-prepared-statement
jdbc.clj: 1024 clojure.java.jdbc/db-do-execute-prepared-statement
jdbc.clj: 1062 clojure.java.jdbc/db-do-prepared
jdbc.clj: 1042 clojure.java.jdbc/db-do-prepared
jdbc.clj: 1446 clojure.java.jdbc/execute!/execute-helper
jdbc.clj: 1450 clojure.java.jdbc/execute!
jdbc.clj: 1417 clojure.java.jdbc/execute!
jdbc.clj: 1438 clojure.java.jdbc/execute!
jdbc.clj: 1417 clojure.java.jdbc/execute!
REPL: 273 ejc-sql.connect/eval10189
REPL: 273 ejc-sql.connect/eval10189
Compiler.java: 7062 clojure.lang.Compiler/eval
Compiler.java: 7025 clojure.lang.Compiler/eval
core.clj: 3206 clojure.core/eval
core.clj: 3202 clojure.core/eval
main.clj: 243 clojure.main/repl/read-eval-print/fn
main.clj: 243 clojure.main/repl/read-eval-print
main.clj: 261 clojure.main/repl/fn
main.clj: 261 clojure.main/repl
main.clj: 177 clojure.main/repl
RestFn.java: 1523 clojure.lang.RestFn/invoke
interruptible_eval.clj: 79 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 55 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 142 nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
AFn.java: 22 clojure.lang.AFn/run
session.clj: 171 nrepl.middleware.session/session-exec/main-loop/fn
session.clj: 170 nrepl.middleware.session/session-exec/main-loop
AFn.java: 22 clojure.lang.AFn/run
Thread.java: 748 java.lang.Thread/run
- Ok, first of all, please update
ejc-sql
frommaster
. It usesorg.clojure/java.jdbc
from upstream. - Then please try the newest connection configuration parameters:
(ejc-create-connection
"my-db-conn"
:classpath "/home/rrudakov/.m2/repository/postgresql/postgresql/9.3-1102.jdbc41/postgresql-9.3-1102.jdbc41.jar"
:dbtype "postgresql"
:dbname "dbname"
:host "hostname"
:port "5432"
:user "a_user"
:password "secret")
- Also, you can try the newest PostgreSQL JDBC driver (https://github.com/pgjdbc/pgjdbc):
mvn org.apache.maven.plugins:maven-dependency-plugin:get -Dartifact=org.postgresql:postgresql:42.2.5
then update ejc-create-connection
:
(ejc-create-connection
...
:classpath "/home/rrudakov/.m2/repository/postgresql/postgresql/42.2.5/postgresql-42.2.5.jar
...
- If no luck with previous steps, it's worth to try run JDBC without clojure/java.jdbc wrapper at all, e.g.: https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html I case of success with only this approach, please, open an issue in clojure/java.jdbc - Jira directly.
Seems like it works now. Thank you very much.
You are welcome. Feel free to ask about ejc-sql
usage and feature requests.
Hi @kostafey ,
I'm getting the same error trying to execute INSERT/CREATE TABLE
I tried also to run with the master version of ejc-sql (lein repl and connecting from emacs), but still get the same.
And also j/execute!
directly in the repl returns the same error.
Any suggestions about how to debug/fix it?
@AndreaCrotti Could you please update ejc-sql
to try with newest org.clojure/java.jdbc "0.7.10"
from upstream.
If no luck with it, could you provide the database type and JDBC driver you use for access.
Actually I was already trying with 0.7.10, I just ran alein ancient upgrade
before trying.
The db is a Postgres instance in a docker container
services:
pg:
image: postgres:10.4
ports:
I can try with some other version too potentially if that could the issue.
I also tried now with Postgres 12.1 to see if it made a difference but I get the same result..
@AndreaCrotti, could you provide your database configuration created by ejc-create-connection
with mangled username and password, please?
I have the same problem - namely, if I try to do INSERT
or CREATE TABLE
I get:
Error: This ResultSet is closed.
I could provide the appropriate versions, or better errors, if I knew how, @kostafey.
An interesting tidbit I noticed though: when I connect via ejc-connect-interactive
I get this error:
2. Unhandled clojure.lang.Compiler$CompilerException
Error compiling *cider-repl build-28.0.91/ejc-sql:localhost:36775(clj)* at (11:85)
...
1. Caused by java.lang.RuntimeException
Unable to resolve symbol: tap> in this context