Cover by Brian Carper, Christophe Grand, Chas Emerick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

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. clojure.java.jdbc 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.

clojure.java.jdbc

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 clojure.java.jdbc (https://github.com/clojure/java.jdbc) 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 clojure.java.jdbc ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required