Web Development with Clojure, Third Edition - Appendix 4 (Database Access) p. 395

Dmitri Sotnikov @dmitri and Scot Brown @svmbrown

Hi all,
I’m working through the Appendix 4 (Database Access) starting on p. 395 and there are a number of discrepancies with what’s in the book vs. what actually will execute. So I will document here as I make my way through.

On p. 397,

(def ds (jdbc/get-datasource
{:subprotocol “postgresql”
:subname “//localhost/reporting
:user “admin”
:password “admin”}))

In the preceding example, we’ve defined a connection for an instance of the
PostgreSQL database by specifying the database type using the :dbtype key and a name using the :dbname key.

The above did not work for me and I got this error:

error {
:cause Unknown dbtype: , and :classname not provided.
:data {:subprotocol postgresql, :subname //localhost/reporting, :user admin, :password admin}
:via
[{:type clojure.lang.Compiler$CompilerException

Notice that :dbtype & :dbname are not in the hashmap (as the error message indicates and the sentence in the book itself indicates we should be using) so using this hashmap works (I also had to remove the “//local/” prefix in the dbname.

(def ds (jdbc/get-datasource
{:dbtype “postgresql”
:dbname “reporting”
:user “admin”
:password “admin”}))

After executing, I get:

[#:next.jdbc{:update-count 0}]

which is what the book says we should get.