Menu

Persistence Using Java

Project Digitisation: I have decided to convert the notes that I have written into blogs 🙂 This post and some posts that follow(about JPA) is part of that project.

There are several frameworks that are used for persisting objects in databases like JPA, Hibernate etc. (JPA is actually a specification. Hibernate is an implementation of JPA. Hibernate also has several extra features which are not specified by JPA).

This blog post mentions JDBC. I will not go into the details of how to use JDBC as using JPA is the focus. Details about how to persist objects in Java using JPA is discussed in next blog post.

JDBC

JDBC – Java DataBase Connectivity
JDBC works in the backstage of all the frameworks. Frameworks makes our life easy in persisting objects and modifying them.
JDBC is a specification – it tells the DB vendor how to provide driver for Java and it tells the programmer how to write Java programs that can connect to the db. It is in “java.sql” package.
JDBC drivers:

Type 1 (JDBC – ODBC Bridge) – obsolete

Type 2 (Native API Driver) – obsolete

Type 3 (Network Protocol Driver)

Type 4 (Native Protocol Driver)

Type 4 is NOT an improvement over Type3.
Type 3 communicates with Application Servers. So even if we change databases, the programs need not be changed. The application server automatically selects the suitable driver.
Type 4 is specific to each DB vendor. If we change the vendor then we need new driver. It is platform independent.