Fork me on GitHub

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.

  (: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


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


ah, interesting!


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


oh gosh, what a headache! all the more props to you