Summary: in this tutorial, you will learn about JDBC and JDBC drivers.
Introduction to JDBC
JDBC stands for Java Database Connectivity.
JDBC provides a standardized way for you to write applications that can interact with various database systems including:
- MySQL
- Oracle
- PostgreSQL
- SQL Server
- MariaDB
- And other database systems.
By using JDBC, you can write database-independent code. It means you can use the same code to interact with different databases, without rewriting or having a separate part of application logic to handle each database individually.
JDBC is a Java API that allows you to interact with a database including:
- Creating a new database connection.
- Inserting data into a table.
- Updating data in a table.
- Deleting data from a table
- Retrieving data from a table
- Executing stored procedures or functions if the database supports them.
You can think of JDBC as a middleman standing between a Java application and a database.
What is a JDBC Driver
To connect to a database from a Java application using JDBC, you need a JDBC driver for that particular database:
A JDBC driver is a Java library containing classes that implement JDBC API.
Typically, the database vendors provide the JDBC drivers as a library jar or a Java module.
JDBC is evolving. Therefore, please be sure that you work with a driver that supports at least JDBC version 4.0.
Here are some notable features in JDBC 4.0 and later:
- Auto-loading JDBC driver
- Built-in connection pooling
- Distributed transaction
- Row streaming
- SQLXML support.
- Try-with-resource statement support
It’s fine if all of these features do not make any sense to you for now. We’ll cover them in the upcoming tutorials.
JDBC packages
JDBC consists of two main packages that provide API for accessing the databases:
- java.sql offers the API for accessing and managing databases.
- javax.sql is an extension of the java.sql package to support more advanced database operations, connection pooling, distributed transactions, and other enterprise-level features
Summary
- JDBC stands for Java Database Connectivity.
- JDBC offers a standardized API for Java applications to interact with various database systems.