我正在尝试使用Korma连接到Oracle数据库。首先,我尝试使用此代码并成功连接。
(defdb korma-db
{:classname "oracle.jdbc.OracleDriver"
:subprotocol "oracle"
:subname "thin:@my.oracle.db:1521:testdb"
:user "xxx"
:password "xxx"
:naming {:keys str/lower-case :fields str/upper-case}})但是我发现有一个更方便的函数korma.db.oracle。因此,代码看起来应该简化如下:
(defdb korma-db
(oracle {:keys ["my.oracle.db" 1521 true]
:as {:user "xxx" :password "xxx"}
:naming {:keys str/lower-case :fields str/upper-case}}))但失败了。它试图localhost。当我检查oracle函数的结果时,我发现有一些奇怪的东西。
{:naming {:keys #<string$lower_case clojure.string$lower_case@5ba760ac>,
:fields #<string$upper_case clojure.string$upper_case@504f4c0b>},
:as {:user "xxx", :password "xxx"},
:keys ["my.oracle.db" 1521 true],
:classname "oracle.jdbc.driver.OracleDriver",
:subprotocol "oracle:thin",
:subname "@localhost:1521", :make-pool? true}
^^^^^^^^^我检查了Korma源代码,oracle函数的代码是:
(defn oracle
"Create a database specification for an Oracle database. Opts should include keys
for :user and :password. You can also optionally set host and port."
[{:keys [host port make-pool?]
:or {host "localhost", port 1521, make-pool? true}
:as opts}]
(merge {:classname "oracle.jdbc.driver.OracleDriver" ; must be in classpath
:subprotocol "oracle:thin"
:subname (str "@" host ":" port)
:make-pool? make-pool?}
opts))简而言之,我的问题是:
oracle函数的确切用法是什么?我遗漏了什么?oracle函数的代码对我来说很奇怪。有谁能解释一下代码,特别是参数部分.[{:keys [host .... ] :or {...} :as ...}]发布于 2013-12-20 09:16:22
这个oracle函数破坏其论点。这是一个关于这一特性的文章。
因此,调用oracle的正确方法是:
(defdb korma-db
(oracle { :user "xxx"
:password "xxx"
:host "my.oracle.db"
:port 1521
:make-pool? true }))编辑:指定oracle SID可以如下所示:
(defdb korma-db
(oracle {:subname "@//xxx.xxx.xxx.xxx:1521/testdb"
:user "xxx"
:password "xxx"
:naming {:keys str/lower-case :fields str/upper-case}}))https://stackoverflow.com/questions/20699329
复制相似问题