0

I'm trying to pass something like this in clojure

(def pg-uri {:connection-uri "jdbc:postgresql://user:[email protected]:12345/defaultdb?sslmode=verify-full&options=--cluster%3Dfoobar"})

(defn query [q]
  (let [conn (j/get-connection pg-uri)]
  (j/query pg-db q))

(query (-> (select :*) (from :user) (sql/format)))

but am getting ; Execution error (SocketTimeoutException) at sun.nio.ch.NioSocketImpl/timedFinishConnect (NioSocketImpl.java:539). ; Connect timed out

I was wondering how I can fix this. I'm able to connect just fine using another client. Thank you

1 Answer 1

1

In JDBC URLs (at least, in the jdbc:postgresql: ones), the password and the username must be specified as parameters and not in front of the server:

(org.postgresql.Driver/parseURL
  "jdbc:postgresql://host.aws-us-west-2.cockroachlabs:12345/defaultdb?sslmode=verify-full&user=user&password=password&options=--cluster%3Dfoobar"
  nil)
=>
{"sslmode" "verify-full",
 "PGDBNAME" "defaultdb",
 "PGPORT" "12345",
 "PGHOST" "host.aws-us-west-2.cockroachlabs",
 "password" "password",
 "options" "--cluster=foobar",
 "user" "user"}
Sign up to request clarification or add additional context in comments.

1 Comment

This came up recently with next.jdbc (the OP here is using clojure.java.jdbc) and I modified next.jdbc to support this but left it undocumented since I do not want to encourage people to use incorrectly-formatted JDBC URLs: github.com/seancorfield/next-jdbc/issues/229

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.