Computer Science Related Others Courses AvailableThe Best Codder.blogspot.com

JDBC Package in Java

JDBC-Package-Java

 

Java Package JDBC 

JDBC stands for Java Database Connectivity. JDBC is a Java API to connect and execute the query with the database. It is a part of JavaSE (Java Standard Edition). JDBC API uses JDBC drivers to connect with the database. There are four types of JDBC drivers:

  • JDBC-ODBC Bridge Driver,
  • Native Driver,
  • Network Protocol Driver, and
  • Thin Driver
The JDBC (Java Database Connectivity) API is a Java API that provides a standard interface for connecting Java applications to databases. The JDBC API allows developers to write database applications in Java without having to learn SQL or other database-specific languages. The JDBC API is part of the Java Standard Edition (Java SE) and includes the java.sql and javax.sql packages.

The java.sql package provides the core JDBC API, including classes for connecting to databases, executing SQL statements, retrieving results, and working with transactions. Some of the key classes in the java.sql package include:

DriverManager: Provides methods for establishing a connection to a database.
Connection: Represents a connection to a database and provides methods for creating statements and managing transactions.
Statement: Represents an SQL statement that is sent to a database for execution.
ResultSet: Represents the result set of an SQL query and provides methods for retrieving data.
The javax.sql package provides additional classes and interfaces for working with databases in a more sophisticated way, such as connection pooling, distributed transactions, and support for database metadata.

To use the JDBC API in your Java application, you need to include a JDBC driver for the database you are connecting to in your classpath. The JDBC driver provides the implementation of the JDBC API for a specific database. Each database vendor provides its own JDBC driver, which you can download from the vendor's website or through a third-party provider. Once you have the JDBC driver, you can use the DriverManager class to connect to the database and execute SQL statements.

We have discussed the above four drivers in the next chapter.

We can use JDBC API to access tabular data stored in any relational database. By the help of JDBC API, we can save, update, delete and fetch data from the database. It is like Open Database Connectivity (ODBC) provided by Microsoft.

JDBC (Java Database Connectivity)

The current version of JDBC is 4.3. It is the stable release since 21st September, 2017. It is based on the X/Open SQL Call Level Interface. The java.sql package contains classes and interfaces for JDBC API. A list of popular interfaces of JDBC API are given below:

  • Driver interface
  • Connection interface
  • Statement interface
  • PreparedStatement interface
  • CallableStatement interface
  • ResultSet interface
  • ResultSetMetaData interface
  • DatabaseMetaData interface
  • RowSet interface

A list of popular classes of JDBC API are given below:

  • DriverManager class
  • Blob class
  • Clob class
  • Types class

Why Should We Use JDBC

Before JDBC, ODBC API was the database API to connect and execute the query with the database. But, ODBC API uses ODBC driver which is written in C language (i.e. platform dependent and unsecured). That is why Java has defined its own API (JDBC API) that uses JDBC drivers (written in Java language).

We can use JDBC API to handle database using Java program and can perform the following activities:

  1. Connect to the database
  2. Execute queries and update statements to the database
  3. Retrieve the result received from the database.

What is API

API (Application programming interface) is a document that contains a description of all the features of a product or software. It represents classes and interfaces that software programs can follow to communicate with each other. An API can be created for applications, libraries, operating systems, etc.


Post a Comment

© JAVA. The Best Codder All rights reserved. Distributed by