Question

I am using the SpringSource Informix JDBC driver for Clojure. I am getting an error when loading a file using lein repl (load-file ...) Here is the error:

No such var: j/with-connection

What am I doing wrong?

This function returns a database map to be used with a query (along with core.clj header)

(ns ics-db.core
  (require [clojure.string :as str])
  (require [clojure.java.jdbc :as j])
  (require [util.core :as utl])
  (:use [clojure.tools.cli])
  (:use [clojure.java.shell :only [sh]])
  (:import java.util.Date)
)

(def dbg 2)

(def if_SE_engine_type "SE")

(defn retn-informix-setup
"Sets up and returns a map structure that can be used elsewhere to talk to informix/ics"
[opts]
(let [start-time  (str (Date.))
  informix-db {:classname "com.informix.jdbc.IfxDriver"
               :subprotocol "informix-sqli"
               :subname (format "//%s:%s/%s:informixserver=%s;usev5server=1;DBPATH=%s" 
               (:host opts)
               (:port opts)
               (:database opts)
               (:server opts)
               (:dbpath opts))
              }]
  informix-db))

This function takes the db map created above, and the select query works fine.

(defn ret-sel-query
  "Performs a selection query."
  [db-info query]
  (let [result (j/query db-info
                     [query])]
    result)) 

This is the function containing the j/with-connection that fails. This function tries to delete the row just queried:

(defn del-query
  "Performs a delete query."
  [db-info id]
  (let [result (j/with-connection db-info
                (j/delete-rows :real_estate [:acct_no id]))]))

This test function tests the select and delete. If I remove the code that attempts the delete, the selected row is selected, returned, and the println prints the row.

(if (>= (utl/chk-flagM dbg) 2)
  (do
      (defn test-1
        []
        (let [opts {:host "steamboy", 
                    :server "steamboy",
                    :database "ics",
                    :port 1498,
                    :dbpath "/home/ics/icsdev/"}

              informix-db (retn-informix-setup opts)

              sel-q "select r.* from real_estate r where r.acct_no = 70782"

              q-result (ret-sel-query informix-db sel-q)

              _  (del-query informix-db 70782)]



          (println q-result)))))

This modified function works, but I am wondering why the with-connection does not.

(defn del-query
  "Performs a delete query."
  [db-info id]
  (j/delete! db-info :real_estate ["acct_no = ?" id]))
Was it helpful?

Solution

clojure.java.jdbc 0.3.x deprecated those functions. They are now accessible via the namespace clojure.java.jdbc.deprecated. So either use that namespace, transform your code to use the new API or go back to an older version of the library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top