错误“没有这样的名称空间:JDBC”当需要Next.jdbc在clojure中
我尝试时遇到了需求或下一步。 创建一个Postgres数据库:
Unhandled java.io.FileNotFoundException
Could not locate next/jdbc__init.class, next/jdbc.clj or next/jdbc.cljc on
classpath.
以及以下内容。无论何时我尝试在cljblog.db名称空间中调用JDBC函数。
1. Caused by java.lang.RuntimeException
No such namespace: jdbc
这是我的数据库设置:
(ns cljblog.db)
(require '[next.jdbc :as jdbc])
(def db
{:dbtype "postgresql"
:dbname "cljblog"
:host "localhost"
:user "postgres"
:password "postgres"})
(def ds (jdbc/get-datasource db))
(def ds (jdbc/get-datasource db))
(def conn (jdbc/get-connection ds))
(jdbc/execute! conn ["
-- postgresql version
drop table if exists posts?;
create table posts (
id int,
title varchar(255),
body text,
author varchar(25)
"])
(jdbc/execute! conn ["
insert into posts(title,body,author)
values('Working with postgres',
'this is my first attempt at working
with postgres in Clojure', 'Sam Dees')"])
(def result-set
(jdbc/execute!
conn
["select * from posts"]))
project.clj
(defproject cljblog "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.10.0"]
[compojure "1.6.1"]
[ring/ring-defaults "0.3.2"]
[hiccup "1.0.5"]
[com.github.seancorfield/next.jdbc "1.2.780"]
[org.postgresql/postgresql "9.4-1201-jdbc41"]]
:plugins [[lein-ring "0.12.5"]]
:ring {:handler cljblog.handler/app}
:repl-options {:init-ns clj-jdbc.core}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.2"]]}})
*我已经将完整的错误消息截断为简洁。 *Postgres是在系统上运行的活动服务器安装的
I'm running into require and or next.jdbc errors when I attempt
to create a postgres database:
Unhandled java.io.FileNotFoundException
Could not locate next/jdbc__init.class, next/jdbc.clj or next/jdbc.cljc on
classpath.
and the following. Which appears anytime I attempt to call jdbc functions within the cljblog.db namespace.
1. Caused by java.lang.RuntimeException
No such namespace: jdbc
Here's my db setup:
(ns cljblog.db)
(require '[next.jdbc :as jdbc])
(def db
{:dbtype "postgresql"
:dbname "cljblog"
:host "localhost"
:user "postgres"
:password "postgres"})
(def ds (jdbc/get-datasource db))
(def ds (jdbc/get-datasource db))
(def conn (jdbc/get-connection ds))
(jdbc/execute! conn ["
-- postgresql version
drop table if exists posts?;
create table posts (
id int,
title varchar(255),
body text,
author varchar(25)
"])
(jdbc/execute! conn ["
insert into posts(title,body,author)
values('Working with postgres',
'this is my first attempt at working
with postgres in Clojure', 'Sam Dees')"])
(def result-set
(jdbc/execute!
conn
["select * from posts"]))
and the project.clj
(defproject cljblog "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.10.0"]
[compojure "1.6.1"]
[ring/ring-defaults "0.3.2"]
[hiccup "1.0.5"]
[com.github.seancorfield/next.jdbc "1.2.780"]
[org.postgresql/postgresql "9.4-1201-jdbc41"]]
:plugins [[lein-ring "0.12.5"]]
:ring {:handler cljblog.handler/app}
:repl-options {:init-ns clj-jdbc.core}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.2"]]}})
*I've truncated the full error messages for brevity.
*postgres is installed with an active server running on the system
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您在添加这些依赖项后重新启动了重新启动,则您的
ns
表格应该看起来像这样:此外,您还有:
但是您没有向我们显示该名称空间(在文件
src/clj_jdbc中我怀疑的/core.clj
)确实发生了错误。Assuming you restarted your REPL after adding those dependencies, your
ns
form should look like this:In addition, you have:
but you didn't show us that namespace (in the file
src/clj_jdbc/core.clj
) which I suspect is where the error is really occurring.您可能希望与
next.jdbc
一起使用postgres克隆此演示项目,以供访问:https://github.com/cloojure/demo-jdbc-next
遵循读书中的说明,它应该立即起作用。还提供了与H2数据库一起使用
next.jdbc
的示例。当您运行测试时,您将看到所有工作:
所有操作都在测试名称空间中。文件
test/tst/demo/jdbc_postgres.clj
开始这样的开始:我注意到您似乎在
project.clj
中似乎有问题。我的看起来像:因此,对
org.postgresql/postgresql
的依赖性可能是问题的一部分。You may wish to clone this demo project using Postgres in a Docker container along with
next.jdbc
for access:https://github.com/cloojure/demo-jdbc-next
Follow along the instructions from the README and it should work right away. There are also examples of using
next.jdbc
with the H2 database.When you run the tests, you will see everything working:
All of the action is in the test namespaces. The file
test/tst/demo/jdbc_postgres.clj
starts out like so:I've noticed that you seem to have something wrong in your
project.clj
. Mine looks like:so the dependency on
org.postgresql/postgresql
may be part of the problem.