JDBC   «Prev  Next»
Lesson 1

Connecting Java Application using JDBC

This module will introduce you to how you can connect a Java program to a database.
You are likely aware that a major strength of Java is its system independence. An early slogan for Java was "write once, run anywhere." While that slogan slightly exaggerates the portability of Java applications, that spirit extends to nearly all the services available for those applications. Database services are no exception. The architects for these services attempted to provide a similar level of independence for those database services. This is the JDBC API.
JDBC is not an acronym or an abbreviation. Sun (now Oracle) had trademarked the term "JDBC' but never officially designated that the letters represented a phrase. Often, people assign their own meaning to it, usually a phrase such as "Java Database Connectivity," but that is not an association created by Sun or Oracle. JDBC is a Java-based data access technology (Java Standard Edition platform) from Oracle Corporation. This technology is an API for the Java programming language that defines how a client may access a database. It provides methods for querying and updating data in a database and the JDBC API facilitates communication with relational databases. A JDBC-to-ODBC bridge enables connections to any ODBC-accessible data source in the JVM host environment.


Oracle JDBC Drivers

(APIs), Oracle drivers have extensions to support Oracle-specific data types and to enhance performance. Oracle provides the following JDBC drivers:
  1. Thin driver: It is a pure Java driver used on the client side, without an Oracle client installation. It can be used with both applets and applications.
  2. Oracle Call Interface (OCI) driver: It is used on the client-side with an Oracle client installation. It can be used only with applications.
  3. Server-side Thin driver: It is functionally similar to the client-side Thin driver. However, it is used for code that runs on the database server and needs to access another session either on the same server or on a remote server on any tier.
  4. Server-side internal driver: It is used for code that runs on the database server and accesses the same session. That is, the code runs and accesses data from a single Oracle session.

Figure 3-1 illustrates the architecture of the Oracle JDBC drivers and the Oracle Database.
Architecture of the Oracle JDBC Drivers and Oracle Database
Figure 3-1 Architecture of the Oracle JDBC Drivers and Oracle Database

JDBC History

Any Java class can use JDBC to connect with a database using a driver. JDBC has been around since 1997, and was added to JSE 1.1 as JDBC 1.0. Since its first version, multiple enhancements have been made to the JDBC API. Java 7 ships with JDBC version 4.1. JDBC classes are defined in Java packages java.sql and javax.sql. By using the classes and interfaces from the JDBC API, Java classes can connect to a data source, execute SQL (Structured Query Language, the standard language for relational database management systems, RDBMS), and process the results. At the heart of the JDBC API lies the use of SQL to create, modify, and delete database objects like tables, and query and update them. JDBC provides vendor-neutral access to the common database features. Hence, you do not use proprietary features of a database and can easily change the database that you connect to. The JDBC API includes an abstraction of a
  1. database connection,
  2. statements, and
  3. result sets.

Features, Benefits, Capabilities of JDBC

An important feature of JDBC is that it provides an application developer with the capability to use the information collected in a database management system (DBMS). In this module, you will learn about the capabilities that JDBC encompasses for a Java programmer who must use that information. You will also learn about database systems, the different types of database systems that are available and why they are important for an organization. We will discuss the relationship between a DBMS and JDBC.

JDBC Case Study

Like all organizations, the Brazilian Hospital Project wants to get its work completed in the most efficient manner possible.
They want to focus their resources on analyzing the data they will collect. A computer system is a tool to accomplish that objective. Because of that, they want their computer system to help them reach that goal with a minimum of trouble and expense. In addition, they want a system that can easily change or grow as circumstances require.
Because of those requirements, they chose to use Java and JDBC for the development of their computer system. Java and JDBC can provide the efficiency and flexibility they require. The system could be written to run on a wide range of systems, from inexpensive Linux machines to clustered mainframes, with a minimum of changes. Now, you must learn how to use the tools provided by JDBC to utilize those features of Java for your client.


Module Objectives

After completing this module, you will have the skills and knowledge that will enable you to:
  1. Distinguish the role and place of JDBC among the Java technologies
  2. Differentiate between DBMS types
  3. Explain the relational model
  4. Describe design considerations for JDBC and ODBC in a solution
  5. Explain what SQL is and its role in database processing
  6. Explain JDBC as it functions in two and n-tier systems designs
  7. Describe the capabilities of Java and a DBMS used with JDBC
In the next lesson, you will learn about the role of JDBC among the Java technologies.

SEMrush Software