This answer applies to postgresql instead of MySQL, but should apply to both.
Wrap your query-results function with (clojure.java.jdbc / transaction), therefore:
(let [query (query-only (fetch-all big-table))] (clojure.java.jdbc/with-connection (get-connection (:db query)) (clojure.java.jdbc/transaction (clojure.java.jdbc/with-query-results rows (into [{:fetch-size Integer/MIN_VALUE :concurrency :read-only :result-type :forward-only} (:sql-str query)] (:params query)) (throw (Exception. (str "retrieved a row: " (pr-str (first rows))))))))))
The postgresql docs specifies another requirement for enabling streaming: "The connection should not be in autosave mode." By default, a connection is created using autocommit, but using (clojure.java.jdbc / transaction), internal code will be executed with autocommit disabled. You can also call .setAutoCommit directly from your connection.
source share