Closed theronic closed 10 years ago
Ah, sorry I had to put the (.close conn)
outside the tx/with-transaction
:
(defn build-schema []
(let [conn (make-connection dbspec)]
(with-catch
(tx/with-transaction conn
(doseq [[cmd] my-schema]
(execute! conn cmd)))
(.close conn))))
You also can use with-open
clojure macro :D
(with-open [conn (make-connection dbspec)]
your code here...)
You can see few options to open a connection here: http://niwibe.github.io/clojure.jdbc/#_creating_a_connection
How can I reuse the same connection to run multiple SQL commands? When I eval my
(build-schema)
defined below, I get the error:Here is a mock schema using SQLingvo:
Here is my build-schema function that doseq's over my schema: