This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-20
Channels
- # aleph (11)
- # announcements (3)
- # babashka (35)
- # babashka-sci-dev (28)
- # beginners (29)
- # calva (51)
- # cider (33)
- # clj-kondo (26)
- # clj-on-windows (1)
- # clojure (40)
- # clojure-austin (1)
- # clojure-europe (47)
- # clojure-nl (9)
- # clojure-norway (7)
- # clojure-uk (5)
- # clojurescript (69)
- # conjure (30)
- # cursive (7)
- # data-science (9)
- # datomic (2)
- # etaoin (10)
- # events (2)
- # fulcro (1)
- # graalvm (1)
- # gratitude (6)
- # helix (16)
- # honeysql (20)
- # hyperfiddle (14)
- # inf-clojure (2)
- # jobs (1)
- # jobs-discuss (12)
- # kaocha (9)
- # leiningen (2)
- # lsp (4)
- # malli (8)
- # music (9)
- # off-topic (12)
- # pathom (10)
- # portal (14)
- # practicalli (15)
- # re-frame (27)
- # reitit (7)
- # remote-jobs (4)
- # sci (37)
- # shadow-cljs (16)
- # sql (8)
- # tools-deps (6)
- # vim (6)
- # xtdb (21)
Fun next-jdbc behavior
Hey y’all, I just spent most of the afternoon discovering this and I was wondering if the behavior is a feature/expected/I just don’t understand something, or maybe it’s a bug in next-jdbc, or who knows. The README of the project says to say hi in slack ,so I’m saying hi here!
basically when I use get-datasource
with the :jdbcUrl
argument format, I get a ; (err) No suitable driver found for jdbc:
error when the dbtype is postgres
but not when it’s postgresql.
(ns hello.world
(:require [next.jdbc :as jdbc])
;this works
(jdbc/execute! (jdbc/get-datasource "jdbc:")
["select * from user limit 1"])
;this works
(jdbc/execute! (jdbc/get-datasource {:dbtype "postgresql" :name "db_name" :host "localhost" :port "3300"})
["select * from user limit 1"]))
;this also works
(jdbc/execute! (jdbc/get-datasource {:dbtype "postgres" :name "db_name" :host "localhost" :port "3300"})
["select * from user limit 1"]))
;throws the 'no suitable driver' error
(jdbc/execute! (jdbc/get-datasource "jdbc:")
["select * from user limit 1"])
I would have expected postgres to work just as well as postgresql since they’re mentioned side by side https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.2.780/api/next.jdbc?q=get-datasource#get-datasourceIf you're using :jdbcUrl
, it gets passed straight to JDBC and next.jdbc
has basically nothing to do with it -- so you need to pass a URL that JDBC understands.
If you use the next.jdbc
hash map format -- with :dbtype
-- then next.jdbc
can provide some shortcuts and aliases for things. It's why I recommend using the hash map approach.
jeez. i truly did just spend, like, half of my work day tracing down 2 missing characters. anyway, thanks for the speedy reply!
JDBC is a labyrinth, unfortunately, and behavior varies a lot across different databases, despite it being a "standard". next.jdbc
does what it can to make that a bit less painful but there are some things it can't "fix" 🙂 For example, PostgreSQL is alone in returning an entire row from an insert
I believe -- other databases just return the keys. SQL Server only returns table names in ResultSet
data in some situations, Oracle never does, other databases always do. Some databases are case-sensitive, some aren't. One database returns nil
for a ResultSet
instead of an empty ResultSet
(like all the other databases do).
MySQL has a different precedence in SQL for SET
than all the other databases 🙂 (I use MySQL primarily so this is a pain I feel regularly).