Skip to content

Instantly share code, notes, and snippets.

@drankard
Created November 3, 2011 08:31
Show Gist options
  • Save drankard/1336042 to your computer and use it in GitHub Desktop.
Save drankard/1336042 to your computer and use it in GitHub Desktop.
clojure jdbc - query with cursor
(def *default-fetch-size* 500)
(defn with-query-results-cursor [[sql & params :as sql-params] func]
(sql/transaction
(with-open [stmt (.prepareStatement (sql/connection) sql)]
(doseq [[index value] (map vector (iterate inc 1) params)]
(.setObject stmt index value))
(.setFetchSize stmt *default-fetch-size*)
(with-open [rset (.executeQuery stmt)]
(func (resultset-seq rset))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment