Lesson 8
JDBC Database Management Conclusion
Connect to databases using JDBC.
This module gave you the skills and knowledge to enable you to connect to a DBMS using JDBC.
Specifically, you have learned to:
- Describe the different pieces of the JDBC specification
- Write JDBC URLs
- Define the three functions that JDBC drivers perform in the data request process
- Define the purpose of four basic JDBC drivers
- Use the JDBC DriverManager to connect to the DBMS
- Write a simple yet complete JDBC program
In the next module, you will create and populate a database table.
JDBC Programming
JDBC programming can be explained in the following simple steps:
- Importing required packages
- Registering the JDBC drivers
- Opening a connection to a database
- Creating a Statement/PreparedStatement/CallableStatement object
- Executing a SQL query and returning a ResultSet object
- Processing the ResultSet object
- Closing the ResultSet and Statement objects
- Closing the connection
The first hands-on experience with JDBC in this module involves a basic and complete example to illustrate the overall concepts related to creating and accessing data in a database. Here, we assume that a database (MySQL or Oracle) is created and available for use. Database creation is DBMS-specific.
This means that each vendor has a specific set of commands for creating a database. For this obvious reason, database creation commands are not portable (this is the main reason why JDBC has stayed away from database creation commands).
Step 1: Import the Required Packages
Before you can use the JDBC driver to get and use a database connection, you must import the following packages: java.sql and javax.sql.
import java.sql.*;
import javax.sql.*;
To import classes and interfaces properly, refer to the Java Language Specification