I haven't done this with MySQL yet, but I can claim the bonus points
for Postgres! ;-)
The sql library in Clojure Contrib simplifies accessing relational
databases. It supports transactions with commit and rollback, prepared
statements, creating/dropping tables, inserting/updating/deleting
rows, and running queries. The following example connects to a
Postgres database and runs a query.
(use 'clojure.contrib.sql)
(let [db-host "localhost"
db-port 5432
db-name "ct"]
(def db {:classname "org.postgresql.Driver" ; must be in classpath
:subprotocol "postgresql"
:subname (str "//" db-host ":" db-port "/" db-name)
; Any additional keys are passed to the driver
; as driver-specific properties.
:user "mvolkmann"
:password ""})
(with-connection db
(with-query-results rs ["select * from Employee"]
; rs will be a sequence of maps,
; one for each record in the result set.
(dorun (map #(println (:lastname %)) rs)))))
--
R. Mark Volkmann
Object Computing, Inc.