Error "No such namespace: jdbc" when requiring next.jdbc

I’m running into require and or next.jdbc errors when I attempt to create a postgres database:



  Show: Project-Only All 
  Hide: Clojure Java REPL Tooling Duplicates  (25 frames hidden)

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling src/cljblog/db.clj at (12:9)
   #:clojure.error{:phase :compile-syntax-check,
                   :line 12,
                   :column 9,
                   :source "/home/2fo/projects/cljblog/src/cljblog/db.clj"}
             Compiler.java: 6808  clojure.lang.Compiler/analyze
             Compiler.java: 6745  clojure.lang.Compiler/analyze
             Compiler.java: 3820  clojure.lang.Compiler$InvokeExpr/parse
             Compiler.java: 7108  clojure.lang.Compiler/analyzeSeq
             Compiler.java: 6789  clojure.lang.Compiler/analyze
             Compiler.java:   38  clojure.lang.Compiler/access$300
             Compiler.java:  596  clojure.lang.Compiler$DefExpr$Parser/parse
             Compiler.java: 7106  clojure.lang.Compiler/analyzeSeq
             Compiler.java: 6789  clojure.lang.Compiler/analyze
             Compiler.java: 6745  clojure.lang.Compiler/analyze
             Compiler.java: 7180  clojure.lang.Compiler/eval
             Compiler.java: 7131  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  414  clojure.main/repl/read-eval-print/fn
                  main.clj:  414  clojure.main/repl/read-eval-print
                  main.clj:  435  clojure.main/repl/fn
                  main.clj:  435  clojure.main/repl
                  main.clj:  345  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   84  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  152  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  218  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  217  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  829  java.lang.Thread/run

1. Caused by java.lang.RuntimeException
   No such namespace: jdbc

                 Util.java:  221  clojure.lang.Util/runtimeException
             Compiler.java: 7383  clojure.lang.Compiler/resolveIn
             Compiler.java: 7357  clojure.lang.Compiler/resolve
             Compiler.java: 7318  clojure.lang.Compiler/analyzeSymbol
             Compiler.java: 6768  clojure.lang.Compiler/analyze
             Compiler.java: 6745  clojure.lang.Compiler/analyze
             Compiler.java: 3820  clojure.lang.Compiler$InvokeExpr/parse
             Compiler.java: 7108  clojure.lang.Compiler/analyzeSeq
             Compiler.java: 6789  clojure.lang.Compiler/analyze
             Compiler.java:   38  clojure.lang.Compiler/access$300
             Compiler.java:  596  clojure.lang.Compiler$DefExpr$Parser/parse
             Compiler.java: 7106  clojure.lang.Compiler/analyzeSeq
             Compiler.java: 6789  clojure.lang.Compiler/analyze
             Compiler.java: 6745  clojure.lang.Compiler/analyze
             Compiler.java: 7180  clojure.lang.Compiler/eval
             Compiler.java: 7131  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  414  clojure.main/repl/read-eval-print/fn
                  main.clj:  414  clojure.main/repl/read-eval-print
                  main.clj:  435  clojure.main/repl/fn
                  main.clj:  435  clojure.main/repl
                  main.clj:  345  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   84  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  152  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  218  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  217  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  829  java.lang.Thread/run

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}
  :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.

I tried to update the postgres dependency to the following without success.

[org.postgresql/postgresql "42.3.3"]

I’ve tried to answer this on both StackOverflow and the Clojurians Slack. I’m posting this so that others can look in those locations instead of duplicating effort here trying to establish background.

1 Like

Stackoverflow link (easy to find by copy-pasting the thread’s title of course…)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.