CHAPTER 7Working with Databases

Databases are used in many applications. Java enables developers to connect to and use a database via its Java Database Connectivity (JDBC) API. But JDBC is not simple and requires a lot of coding to achieve the simplest of tasks such as connecting to a database, querying tables, and displaying results. Furthermore, the user is always responsible for managing resources, catching exceptions, and closing connections.

Groovy makes working with databases simpler and more efficient by introducing the groovy.sql library package built on top of JDBC. The groovy.sql library also relieves the user of the burden of managing resources and connections, thanks to closures.

In this chapter, I show you how to use Groovy to connect ...

Get Groovy and Grails Recipes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.