Java Reference
In-Depth Information
Chapter 8. Database access
This chapter covers
• JDBC and the Groovy Sql class
• Simplifying Hibernate and JPA using GORM
• Working with the NoSQL database
Virtually every significant application uses persistent data in one form or another. The vast
majority of them save the data in relational databases. To make it easy to switch from one
database to another, Java provides the JDBC [ 1 ] API. While JDBC does handle the required
tasks, its low-level nature leads to many lines of code to handle even the simplest tasks.
1 You would think that JDBC stands for Java Database Connectivity. Everyone would agree with you, except for the
people at Sun (now Oracle) who created the API. They claim that JDBC is a trademarked acronym that doesn't stand
for anything. Clearly lawyers were involved somewhere in the process. I'm not going to be bound by such silliness,
and if I get sued as a result, I'll be sure to blog about it.
Because the software is object-oriented and the database is relational, there's a mismatch
at the boundary. The open source Hibernate project attempts to bridge that gap at a higher
level of abstraction. Java includes the Java Persistence API (JPA) as a uniform interface to
Hibernate and other object-relational mapping (ORM) tools.
Groovy, as usual, provides some simplifications to the Java APIs. For raw SQL, the Groovy
standard library includes the groovy.sql.Sql class. For ORM tools like Hibernate, the
Grails project created adomain-specific language (DSL)called GORM.Finally,manyofthe
so-called “No SQL” databases that have become popular recently also provide Groovy APIs
to simplify their use. Figure 8.1 shows the technologies covered in this chapter.
 
Search WWH ::




Custom Search