Java Database Connectivity
Java JDBC is a java API to
connect and execute query with the database. JDBC API uses jdbc drivers to
connect with the database.
Java Database Connectivity
(JDBC) is an application programming interface (API) for the programming
language Java, which allows to connect and execute query with the database. JDBC
is a part of the Java Standard Edition platform. JDBC provides methods to query
and update data in a database, and is oriented towards relational databases.
The JDBC classes are contained
in the Java package java.sql and javax.sql.
The latest version is JDBC
4.2, and is included in Java SE 8.
JDBC allows multiple
implementations to exist and be used by the same application. The API provides
a mechanism for dynamically loading the correct Java packages and registering
them with the JDBC Driver Manager. The Driver Manager is used as a connection
factory for creating JDBC connections.
JDBC connections support
creating and executing statements. These are SQL's CREATE, INSERT, UPDATE and
DELETE statements, or they may be SELECT statement to query the database.
Also we can execute the stored
procedures available in the database through a JDBC connection.
In order to execute queries in
databases JDBC uses statements using one of the following interfaces:
·
Statement – the
statement is sent to the database server each and every time.
·
PreparedStatement – the
statement is cached and then the execution path is pre-determined on the
database server allowing it to be executed multiple times in an efficient
manner.
·
CallableStatement
–
used for executing stored procedures on the database.
SELECT Query statements return
a JDBC row result set. The row result set is used to iterate over the result
set. Individual columns in a row are retrieved either by name or by column
number. There may be any number of rows in the result set.
Update statements such as
INSERT, UPDATE and DELETE return an update count that indicates how many rows
were affected in the database.