postgresql – Clojure JDBC:无法找到Postgres驱动程序

postgresql – Clojure JDBC:无法找到Postgres驱动程序,第1张

概述我正在开发一个需要与数据库通信的Web服务,所以我正在使用我的基本库来让我访问桌面上的postgres. Jun 5, 2013 1:27:46 PM com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask runWARNING: com.mchange.v2.resourcepool.BasicResourcePool$Acquire @H_403_6@ 我正在开发一个需要与数据库通信的Web服务,所以我正在使用我的基本库来让我访问桌面上的postgres.

Jun 5,2013 1:27:46 PM com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask runWARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@15c313da -- Acquisition     Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource,we Failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:java.sql.sqlException: No suitable driverat java.sql.DriverManager.getDriver(DriverManager.java:264)

在我的数据库库中,我有以下内容

(ns myapp.db     (:import [com.mchange.v2.c3p0 ComboPooledDataSource]))(def specification {    :classname "postgresql"    :subprotocol "org.postgresql.Driver"    :subname "//localhost:5432;database=test"})(defn pooled-data-source [specification]    (let [datasource (ComboPooledDataSource.)]        (.setDriverClass datasource (:classname specification))        (.setJdbcUrl datasource (str "jdbc:" (:subprotocol specification) ":" (:subname specification)))        (.setUser datasource (:user specification))        (.setPassword datasource (:password specification))        (.setMaxIDleTimeExcessConnections datasource (* 30 60))        (.setMaxIDleTime datasource (* 3 60 60))        {:datasource datasource}))(def connection-pool    (delay        (pooled-data-source specification)))(defn connection [] @connection-pool)

然后在我的单元测试中:

(ns myapp.db-test    (:use clojure.test)    (:require [myapp.db]              [clojure.java.jdbc :as jdbc]))(let [db (myapp.db/connection)]    (jdbc/with-connection db)        (jdbc/with-query-results rs ["select * from foo"]            (doseq [row rs]                (println row)))))

但是这在REPL中有效,所以至少我知道数据库已启动并接受连接:

user=> (require '[clojure.java.jdbc :as sql])user=> (sql/with-connection "postgresql://localhost:5432/test"              (sql/with-query-results results ["select * from foo"]                 (doseq [result results] (println result)))){:y 2,:x 1}niluser=>

非常感谢帮助!

我的project.clj如下

(defproject myapp "0.1.0"    :description "myapp"    :dependencIEs [        [org.clojure/clojure "1.5.1"]        [org.clojure/java.jdbc "0.3.0-Alpha4"]        [postgresql "9.1-901.jdbc4"]        [c3p0/c3p0 "0.9.1.2"]])
解决方法 我建议修改你的规范

(def specification {    :subprotocol "postgresql"    :classname "org.postgresql.Driver"    :subname "//localhost:5432/test"})
总结

以上是内存溢出为你收集整理的postgresql – Clojure JDBC:无法找到Postgres驱动程序全部内容,希望文章能够帮你解决postgresql – Clojure JDBC:无法找到Postgres驱动程序所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1159308.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存