Getting started with JDBC
Chapters
What is JDBC?
JDBC know as Java Database Connectivityprovides set of api or standard library for accessing relational databases. Java programs interact with any SQL-compliant database using this api.
JDBC API achieve following tasks:
- Allow to establish connection with supported database
- Sql Query creation
- Method to create and execute stored queries
- Metadata look up
JDBC Architecture:
The JDBC API supports both three-tier and two-tier models for database access but consists of two layers:
- JDBC API: This allows connection between application and JDBC Manager.
- JDBC Driver API: This allows Driver Connection to JDBC Manager.
The JDBC API uses drivers which are database-specific and driver manager to provide connectivity to databases.
The JDBC driver manager communicates with vendor-specific driver that performs real communication with database.
JDBC-ODBC Bridge plus ODBC Driver (Type 1): Driver use ODBC driver to connect to database servers.
Native API partly Java technology-enabled driver (Type 2): Driver converts JDBC class to client API for the RDBMS server.
Pure Java Driver for Database Middleware (Type 3): Driver sends the JDBC calls to middleware server to connect different type of databases.
Direct-to-Database Pure Java Driver (Type 4): Driver allows the JDBC calls over the network protocol using the database server.
Common JDBC Components:
The JDBC API has following classes and interfaces:
- Driver Manager:Database drivers list are managed by this class.
- Driver:It is an Interface to communicatewith database server.
- Connection :It is an interface having all methods for contacting with database
- Statement:The objects created interface to SQL statements to database.
- ResultSet:The objects holds data retrieved from database after executing SQL query Statement objects.
- SQLException: The class handles any errors occurring in database application.
The JDBC 4.1 Packages
The JDBC 4.1 is a primary package which includes java.sql and javax.sql.
New features in 4.1 includes
- The ability to automatically close resources of type
Connection
,ResultSet
, andStatement with try-with-resources statement.
- RowSet 1.1: The introduction of the
RowSetFactory
interface and theRowSetProvider
class, which enable you to create all types of row sets supported by your JDBC driver.
Description
This tutorial is focused on getting you started with JDBC 4.1. This tutorial has following parts
- Introduction
- SQL Syntax
- Setting up Environment
- Getting started with some samples
- Connecting to database
- Statements
- Result Sets
- Data Types
- Transactions
- Exception handling
- Batch Processing
- Streaming Data
- More JDBC Examples
Leave your feedback to help us improve next time. Also let us know if you see any errors that needs to be corrected
Prerequisites
Understanding of Java language a must to understand various things in this tutorial
Audience
Absolute beginners who wants to get started with JDBC
Author: Subject Coach
Added on: 8th Mar 2015
You must be logged in as Student to ask a Question.
None just yet!