I am trying to access a Postgres database inside Clojure. I found a ton of sample projects using the database, creating the database as follows:
(def db {:classname "org.postgresql.Driver" :subprotocol "postgresql" :subname "//localhost/testdb" :username "postgres" :password "postgres"})
Then I try to access the database as follows:
(sql/with-connection db (sql/with-query-results recs ["select * from asdf"] (doseq [rec recs] (println rec))))
However, I get this error:
No suitable driver found for jdbc:postgresql://localhost/testdb [Thrown class java.sql.SQLException]
I assume the problem is related to :classname "org.postgresql.Driver" , but I'm not sure what the solution is. I suppose I need to provide this driver, but I'm not sure where to get it or where to put it. There is a download available at postgresql.org - should I download it? Or is there something I can contribute to my project settings to get lein to load it as a dependency? As soon as I succeed, where will he go?
Edit (in response to @mtnygard): I have this in my .clj project:
(defproject hello-www "1.0.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.2.1"] [postgresql/postgresql "8.4-702.jdbc4"] ...]
My postgres version is 8.4:
[/media/data/dev/clojure/hello-www (postgres *)]$ postgres --version postgres (PostgreSQL) 8.4.8
java postgresql clojure jdbc
Topher
source share