Topic 5: Java Database Connectivity - zhamri/CSC584-Enterprise_Programming GitHub Wiki
Goal
To enable students to connect Java web applications to a database using JDBC and perform basic data operations such as inserting and retrieving records.
🎯 Learning Objectives
Students should be able to:
- Explain the role of JDBC in Java applications
- Describe the components of the JDBC API
- Establish a connection between Java and a database
- Execute SQL statements using Java
- Process query results using ResultSet
- Integrate database operations with Servlet and JSP
📌 Topics to Cover
- Overview of Java Database Programming
- What is JDBC
- Importance in enterprise applications
- JDBC API
- DriverManager
- Connection
- Statement / PreparedStatement
- JDBC Drivers
- Types of drivers
- JDBC architecture
- Executing SQL Statements
- INSERT
- SELECT
- UPDATE / DELETE (basic concept)
- ResultSet Object
- Retrieving data from the database
- 2-Tier Client-Server Model
- Application ↔ Database
- JDBC with JSP/Servlet
- Integrating the database into the web application
🛠️ Hands-on Activity
Activity: Student Registration System with Database (JDBC Integration)
Students are required to:
- Create Database Table. Example:
student
| Column | Type |
|---|---|
| id | INT (PK) |
| name | VARCHAR |
| VARCHAR | |
| program | VARCHAR |
- Connect to Database (Servlet)
- Establish JDBC connection
- Use:
DriverManager.getConnection()
-
Insert Data (Create)
- Save form data into the database
- Use
PreparedStatementforINSERT
-
Retrieve Data (Read)
- Retrieve all student records
- Store result in
ResultSet
-
Display Data (JSP)
- Forward data from Servlet to JSP
- Display in table format:
Name Email Program
Ali [email protected] SE
Ahmad [email protected] IT
- (Optional Enhancement)
- Add Update and Delete functionality (CRUD complete)
Expected Output
Students should produce:
- Database table
- Servlet with JDBC connection
- JSP page displaying student list
- Working flow:
HTML Form → Servlet → Database → JSP