Sharing connection pool between next.jdbc and clojure.java.jdbc

I’m currently using clojure.java.jdbc but would like to gradually shift over to next.jdbc. When my app starts, it uses Luminus’ conman to create a hikari-cp connection pool using the statement below.

(conman/connect!
    {:jdbc-url          (str "jdbc:mysql://" host
                             ":" port
                             "/" (ring.util.codec/url-encode name)
                             "?user=" (ring.util.codec/url-encode user)
                             "&password=" (ring.util.codec/url-encode password)
                             "&serverTimezone=UTC"
                             "&jdbcCompliantTruncation=false"
                             "&useUnicode=true"
                             "&characterEncoding=utf8"
                             "&connectionTimeZone=SERVER"
                             "&useSSL=false"
                             )
     :maximum-pool-size 5})

I can run a clojure.java.jdbc query against that pool. However, I can’t use the pool created with this statement to run a query through next.jdbc, I get the error

Execution error (ExceptionInfo) at next.jdbc.connection/spec->url+etc (connection.clj:199).
Unknown dbtype: 

Is it possible to somehow share a connection pool between the two jdbc libraries? By using a connection config that is compatible between both versions?

Yes, we share the connection pool between clojure.java.jdbc and next.jdbc at work. I have no idea what Luminus does or how conman works but I expect it creates a hash map containing :datasource and that is the connection-pooled datasource which c.j.j understands.

In order to work with next.jdbc, get the value of :datasource from that hash map and it should be a “native” JDBC DataSource object which is what next.jdbc expects.

2 Likes

Yes, (:datasource ...) worked, thanks!

FYI: Support more clojure.java.jdbc hash map formats · Issue #207 · seancorfield/next-jdbc (github.com) has been implemented on develop and I’ll make a note here when I cut the next release (you can test it now via [com.github.seancorfield/next.jdbc “1.2.999-SNAPSHOT”] - Clojars).

1 Like

Cool, thanks!

com.github.seancorfield/next.jdbc {:mvn/version "1.2.790"} is available with support for :datasource (and :connection-uri) to make migration from c.j.j easier.

1 Like