Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to execute update statement #92

Open
EOtrade opened this issue Apr 3, 2019 · 18 comments
Open

Unable to execute update statement #92

EOtrade opened this issue Apr 3, 2019 · 18 comments

Comments

@EOtrade
Copy link

EOtrade commented Apr 3, 2019

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

@kostafey
Copy link
Owner

kostafey commented Apr 3, 2019

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).

@EOtrade
Copy link
Author

EOtrade commented Apr 3, 2019

$ 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:
image

@kostafey
Copy link
Owner

kostafey commented Apr 3, 2019

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.

@rrudakov
Copy link

rrudakov commented Apr 3, 2019

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

@kostafey
Copy link
Owner

kostafey commented Apr 3, 2019

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")

@rrudakov
Copy link

rrudakov commented Apr 3, 2019

image
Looks the same.

@kostafey
Copy link
Owner

kostafey commented Apr 4, 2019

What about direct evaluation:

(j/execute! @db (list "UPDATE profiles SET avatar='test' WHERE id=1"))

@rrudakov
Copy link

rrudakov commented Apr 4, 2019


  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

@kostafey
Copy link
Owner

kostafey commented Apr 4, 2019

  1. Ok, first of all, please update ejc-sql from master. It uses org.clojure/java.jdbc from upstream.
  2. 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")
  1. 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
...
  1. 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.

@rrudakov
Copy link

rrudakov commented Apr 5, 2019

Seems like it works now. Thank you very much.

@kostafey
Copy link
Owner

kostafey commented Apr 5, 2019

You are welcome. Feel free to ask about ejc-sql usage and feature requests.

@kostafey kostafey closed this as completed Apr 5, 2019
@AndreaCrotti
Copy link
Contributor

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?

@kostafey
Copy link
Owner

@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.

@AndreaCrotti
Copy link
Contributor

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.

@AndreaCrotti
Copy link
Contributor

I also tried now with Postgres 12.1 to see if it made a difference but I get the same result..

@kostafey
Copy link
Owner

@AndreaCrotti, could you provide your database configuration created by ejc-create-connection with mangled username and password, please?

@meditans
Copy link

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

@ave6990
Copy link

ave6990 commented Jul 11, 2024

I have the same problem.
PostgreSQL 15.5

---project.clj---
...
[org.clojure/java.jdbc "0.7.12"]
[org.postgresql/postgresql "42.7.12"]
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants