English 中文(简体)
PostgreSQL/Clojure的驱动程序问题
原标题:Driver issue with PostgreSQL/Clojure

我正在尝试访问Clojure内部的Postgres数据库。我发现了大量使用数据库的项目示例,设置数据库如下:

(def db
    {:classname "org.postgresql.Driver"
     :subprotocol "postgresql"
     :subname "//localhost/testdb"
     :username "postgres"
     :password "postgres"})

然后我尝试访问数据库,如下所示:

(sql/with-connection db
    (sql/with-query-results recs ["select * from asdf"]
        (doseq [rec recs]
            (println rec))))

但是,我收到了以下错误:

No suitable driver found for jdbc:postgresql://localhost/testdb
  [Thrown class java.sql.SQLException]

我认为问题出在:classname“org.postgresql.Driver”上,但我不确定解决方案是什么。我想我需要提供这个驱动程序,但不确定从哪里获得或放在哪里。可以在postgresql.org/-我应该下载它吗?或者我可以在项目设置中放入一些东西,让lein将其作为依赖项下载吗?一旦我有了它,它会去哪里?


Edit (in response to @mtnygard): I have this in my project.clj:

(defproject hello-www "1.0.0-SNAPSHOT"
    :dependencies [[org.clojure/clojure "1.2.1"]
                   [postgresql/postgresql "8.4-702.jdbc4"]
                   ...]

我的postgres版本是8.4:

[/media/data/dev/clojure/hello-www (postgres *)]$ postgres --version
postgres (PostgreSQL) 8.4.8
最佳回答

你走在正确的轨道上。该异常表示类路径中没有org.postgresql.Driver。

查看jarvana.com,我发现postgres JDBC 4驱动程序的此条目。根据运行时环境的其余部分,还有其他版本可用。您可以通过编辑project.clj文件来添加此依赖项来包括此项:

(defproject xxxxxxx
  ;;; other stuff

  :dependencies [[org.clojure/clojure "1.2.0"]
                 [postgresql/postgresql "9.0-801.jdbc4"]]
 )
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签