What is JDBC?
JDBC refers to the Java Database Connectivity. It provides java API that allows Java programs to access database management systems (relational database). The JDBC API consists of a set of interfaces and classes which enables java programs to execute SQL statements. Interfaces and classes in JDBC API are written in java.
JDBC core components:
The JDBC API consists of the following core components:
- JDBC Drivers
- Connections
- Statements
- ResultSets
1. JDBC Drivers:
JDBC driver is a collection of classes which implements interfaces defined in the JDBC API for opening database connections, interacting with database and closing database connections.
2. Connections:
Before performing any database operation via JDBC, we have to open a database connection. To open a database connection we can call getConnection() method of DriverManager class.
Syntax:
Connection connection = DriverManager.getConnection(url, user, password)
3. Statements:
The JDBC statements are used to execute the SQL or PL/SQL queries against the database. We need a statement for every single query. JDBC API defines the Statement, CallableStatement, and PreparedStatement types of statements.
4. ResultSets:
A query returns the data in the form of ResultSet. To read the query result date ResultSet provides a cursor that points to the current row in the result set.
JDBC Tutorial:
- Steps to connect database in java
- Connect to Oracle database with JDBC driver
- Connect to MySql database with JDBC driver
- JDBC Statement interface
- JDBC Statement creates a table example
- JDBC Statement inserts a record example
- JDBC Statement updates a record example
- Select record using statement JDBC
- Delete record using statement JDBC
- Batch update using statement JDBC
- JDBC PreparedStatement interface
- Create table using PreparedStatement JDBC
- Inserts record using PreparedStatement JDBC
- Update record using PreparedStatement JDBC
- Select record using PreparedStatement JDBC
- Delete record using PreparedStatement JDBC
- Batch update using PreparedStatement JDBC
- JDBC CallableStatement interface
- JDBC CallableStatement Stored procedure IN parameter example
- JDBC CallableStatement Stored procedure OUT parameter
- JDBC CallableStatement Stored procedure batch update
- Store file in database using JDBC
- Retrieve file from database in java
- Store image in database in java
- Retrieve image from database in java
- JDBC transaction management
- JDBC ResultSetMetaData interface
- JDBC DatabaseMetaData interface
- JDBC batch processing
- JDBC driver
JDBC interview questions: