Chapter 14. Using Relational Databases

Relational databases are a mainstay of software development, and have been for decades now. It is a rare organization that does not use an RDBMS somewhere, and a rare programmer that does not find herself needing to get data in and out of one at least occasionally. Java has a rich history of quality support for relational databases via JDBC; thanks to its close relationship via the JVM, Clojure easily and fully takes advantage of that history.

We have many options for interacting with relational databases from Clojure. is a simple yet powerful library that acts as a thin layer between Clojure and JDBC. Korma is another Clojure library that provides a more Clojure-native interface. And finally, if Clojure’s libraries do not suit your style or if you are looking to mix Clojure into an existing Java-based application, you can always fall back to one of the many mature and robust Java database libraries or frameworks. In this chapter, we’ll explore setting up and using Hibernate from Clojure.

Whether you use a native Java library or one of Clojure’s many libraries, connecting to a database in Clojure will always utilize JDBC, the lowest-level API abstraction for interacting with relational databases in Java. The ( library wraps JDBC, so it is easier to use from Clojure:

[org.clojure/java.jdbc "0.1.1"]

In terms of dependencies, you need to pair JDBC and ...

Get Clojure Programming now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.