JDBC API Components
Overview
Let’s learn JDBC API Components in this tutorial. JDBC API is a collection of classes and interfaces that provide database access. Using the JDBC API, we can access any database. The core JDBC API is comprised of two main packages. We automatically get both packages when we download Java on the machine. The two packages are as follows:
- java.sql;
- javax.sql;
JDBC Components
The main JDBC API Components are as follows:
- JDBC Driver
- DriverManager
- Connection
- Statement
- ResultSet
- ResultSet Metadata
JDBC Driver
A JDBC driver is a software component that provides the implementation of the JDBC API for a specific database system. For example, MySQL JDBC driver for Java programming language is: MySQL Connector/J
MySQL Connector/J is the official JDBC driver for the MySQL database. It allows Java applications to connect to and interact with the MySQL database. In general, there are different types of JDBC drivers available.
- Type 1 (JDBC-ODBC Bridge)
- Type 2 (Native API)
- Type 3 (Network Protocol)
- Type 4 (Thin Driver or Pure Java Driver)
DriverManager
DriverManger manages the JDBC drivers and establishes the connection to the database. It uses the JDBC URL to establish the connection to the database. It returns the Connection object on a successful database connection.
Connection
The Connection object represents the session to the connected database. The createStatement() method creates a Statement object to send SQL statements to the database.
Statement
The Statement object is used for executing the SQL statements and returns the SQL query results.
Example: stmt.executeQuery(sqlQuery)
ResultSet
The ResultSet object refers to the SQL query result table. The ResultSet object maintains a cursor pointing to the current row of the query result table. We can use a while loop to iterate through the ResultSet.
—
Java Tutorials
Java Tutorial on this website:
https://www.testingdocs.com/java-tutorial/
For more information on Java, visit the official website :
More information about Oracle Database: