Home > OS >  Clojure: Execution error (SQLException) at java.sql.DriverManager/getConnection (DriverManager.java:
Clojure: Execution error (SQLException) at java.sql.DriverManager/getConnection (DriverManager.java:

Time:08-30

When evaluating, i get the following error:

Execution error (SQLException) at java.sql.DriverManager/getConnection (DriverManager.java:702).

(ns postgres
  (:require [clojure.java.jdbc :as sql])
  )


(println "test")


(def db-spec
  {:dbtype "postgresql"
   :dbname "test"
   :user "dave"
   :password "mypass"})

(defn all-tasks []
  (sql/query db-spec ["SELECT * FROM hello"]))


(all-tasks)

My deps.edn looks like this:

{
 :paths ["test" "src"]
 :deps {clojure.java-time/clojure.java-time {:mvn/version "0.3.2"}
        org.clojure/java.jdbc {:mvn/version "0.7.12"}
        com.stuartsierra/component {:mvn/version "1.1.0"}
        }
 }

What am i doing wrong?

CodePudding user response:

You need to add the database-specific JDBC driver to your :deps.

Neither clojure.java.jdbc (the old, stable, no longer being enhanced library) nor next.jdbc (the modern, well-maintained replacement) provide actual JDBC drivers -- they exist as Clojure wrappers for "generic" JDBC itself.

See https://github.com/seancorfield/next-jdbc/blob/develop/deps.edn for examples of JDBC drivers that next.jdbc has been tested against and https://github.com/clojure/java.jdbc/blob/master/deps.edn for examples of JDBC drivers that clojure.java.jdbc has been tested against (which are generally older and some still provide Java 7 support).

For PostgreSQL, you'll want some version of:

org.postgresql/postgresql {:mvn/version "42.4.1"}

If you are just getting started with Clojure, I strongly recommend you use next.jdbc instead of the older library. Aside from the maintenance status of c.j.j, the documentation for next.jdbc is much better and that's where I'm putting all of my effort these days -- I'm only providing critical security fixes for c.j.j at this point.

  • Related