Chapter 9. Java and Databases

IN THIS CHAPTER

  • Java database connectivity

  • The Hibernate framework

Java has a wide variety of libraries available for working with databases. This chapter discusses two of the most widely used methods of working with databases in Java. The first, Java Database Connectivity, is included with the Java Development Kit. The second, Hibernate, is a separate open-source library.

Java Database Connectivity

Java Database Connectivity (JDBC) has been a standard component of the JDK almost since the beginning. JDK version 6 includes JDBC 4.0. It provides a set of classes that allow you to execute SQL statements and queries against a database and then work with the results. Because it uses standard SQL, developers who are familiar with SQL and running queries against a database are able to pick it up fairly quickly.

Note

For more on databases and SQL, see Chapter 8.

Overview of JDBC

The JDBC classes included with the JDK are part of the java.sql and javax.sql packages. There are a number of classes and interfaces in this package. These include the following:

  • The Connection interface represents a connection to a database. Connection is used to create the statements and queries that are run against the database as well as to retrieve information about the database itself.

  • The Statement interface represents the SQL statement to be run against the database.

  • The PreparedStatement interface is much like the Statement interface, but it also allows the addition of parameters. This ...

Get Java® and Flex® Integration Bible 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.