the general idiom with-some-resource means that resources will be
cleared after leaving its scope. JUst like with 'with-open' which has a
try/finally in order to .close() any closable resource upon exit. I've
not used clojure.java.jdbc but I suspect the same rationale applies for
with-connection...
for example in one of my GUIs I have a 'with-busy-cursor' and a
'with-block' macros. Every time an expensive operation happens on the
gui I want a busy cursor but also I want my buttons to be non-reactive
while the busy-cursor is visible (the user can click but nothing
happens). so imagine i've got the 'with-block' called from inside the
'with-busy-cursor' and that removes all the boilerplate code for
restoring the cursor and the reactive gui...
hope that helps...
Jim
On 09/11/12 17:42, larry google groups wrote:
Sorry this is such an ignorant question, but I am new to Clojure and
the JVM. I am tring to find info about clojure.java.jdbc so I looked here:
http://corfield.org/blog/post.cfm/connecting-clojure-and-mysql
and saw this example:
(ns mysql.core
(:require [clojure.java.jdbc :as sql]))
(def db {:classname "com.mysql.jdbc.Driver"
:subprotocol "mysql"
:subname "//localhost:3306/dbname"
:user "dbuser"
:password "secret"})
(defn list-users []
(sql/with-connection db
(sql/with-query-results rows
["select * from user"]
(println rows))))
Can I assume thatsql/with-connection does some magic in the background to
manage the connection? I would not want the connection to get shut down, and
then restarted, everytime I run a query.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient
with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en