JDBC tutorial for beginners and professionals with examples in eclipse on Basics, Drivers, Setup, SQL, Statement, Insert, Update, Select, Delete, Group By, Where Clause, Pagination, Result Sets, Database and more.
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
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.
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.
Connection connection = DriverManager.getConnection(url, user, password)
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.
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 overview
- JDBC driver
- Steps to connect with DB
- 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
- JDBC Statement select records example
- JDBC Statement deletes a record example
- JDBC Statement batch update example
- JDBC PreparedStatement interface
- JDBC PreparedStatement creates a table example
- JDBC PreparedStatement inserts a record example
- JDBC PreparedStatement updates a record example
- JDBC PreparedStatement select records example
- JDBC PreparedStatement deletes a record example
- JDBC PreparedStatement batch update example
- JDBC CallableStatement interface
- JDBC CallableStatement Stored procedure IN parameter example
- JDBC CallableStatement Stored procedure OUT parameter example
- JDBC CallableStatement Stored procedure batch update example
- JDBC batch processing
- JDBC store file example
- JDBC retrieve file example
- JDBC store image example
- JDBC retrieve image example
- JDBC ResultSetMetaData interface
- JDBC DatabaseMetaData interface
JDBC interview questions: