Home > Blockchain >  jdbc issues error when passing postgresql connection uri for clojure
jdbc issues error when passing postgresql connection uri for clojure

Time:11-19

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=foobar"})

(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

CodePudding user response:

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=foobar"
  nil)
=>
{"sslmode" "verify-full",
 "PGDBNAME" "defaultdb",
 "PGPORT" "12345",
 "PGHOST" "host.aws-us-west-2.cockroachlabs",
 "password" "password",
 "options" "--cluster=foobar",
 "user" "user"}
  • Related