JDBC stands for Java DataBase Connectivity , it is a standard Java API (Application Programming Interface)
for database-independent connectivity between the Java programming language and a wide range of databases.
The JDBC library includes several tasks commonly associated with database usage:
- Making a connection to database
- Creating SQL statements
- Executing the SQL queries in the database
- Viewing or Modifying the records
The Architecture of JDBC is as below :
We use the JDBC API to control the JDBC Driver , then the JDBC Driver can help us to communicate with different kiinds of database system.
We can download the jar file of JDBC for Mysql database from the url as below :
http://dev.mysql.com/downloads/mirror.php?id=404190#mirrors
There are following six steps involved in building a JDBC application:
-
Import the packages .
Include the packages containing the JDBC classes needed for database programming.
Most often, using import java.sql.* will suffice.
-
Register the JDBC driver .
Initialize a driver so you can open a communications channel with the database.
Use Class.forName() to request the ClassLoader to load the driver to the environment of JVM.
-
Open a connection .
Using the DriverManager.getConnection() method to create a Connection object,
which represents a physical connection with the database.
-
Execute a query .
Building and submitting an SQL statement to the database.
-
Extract data from result set .
Use the appropriateResultSet.getXXX() method to retrieve the data from the result set.
-
Clean up the environment .
Closing all database resources versus relying on the JVM's garbage collection.
ref : http://www.tutorialspoint.com/jdbc/jdbc-introduction.htm