Skip to content
Unit 4 Syllabus Note· Web Technologies

Web Technologies

Comprehensive exam revision notes for BCA-303N Unit 4 (Database Access with JDBC, PHP-MySQL & MVC Frameworks). Includes Section A (2M), Section B (5M), and Section C (15M) questions, answers, and diagrams.

Web Technologies

Database Access with JDBC, PHP-MySQL & MVC Frameworks

Core Definitions & Key Concepts

What is JDBC and what layer does it occupy in Java Enterprise architecture

JDBC (Java Database Connectivity) is a standard Java API (java.sql, javax.sql) that defines interfaces for connecting Java applications to relational databases, abstracting vendor-specific database protocols.

Name the four types of JDBC Drivers

  1. Type 1: JDBC-ODBC Bridge Driver (Deprecated)
  2. Type 2: Native-API Driver (Partially Java, requires client library)
  3. Type 3: Network-Protocol Driver (Pure Java, uses middleware)
  4. Type 4: Thin Driver (Direct-to-Database Pure Java - Industry standard)

The difference between Statement and PreparedStatement

FeatureStatementPreparedStatement
Query CompilationCompiled by DB engine every timePre-compiled once, executed repeatedly
PerformanceSlower for repetitive queriesFast due to compiled execution plan
SQL InjectionVulnerable to SQL injectionImmune (parameters bound safely)
SyntaxString concatenation ('" + id + "')Placeholders (?)

What is a CallableStatement in JDBC

CallableStatement extends PreparedStatement to execute Stored Procedures and stored functions located in the database, allowing IN, OUT, and INOUT parameters.

What does ACID stand for in Database Transactions

  • A - Atomicity: All operations complete successfully or all are rolled back.
  • C - Consistency: Database moves from one valid state to another.
  • I - Isolation: Concurrent transactions do not interfere with each other.
  • D - Durability: Committed transaction results survive system crashes.

How do you manage transactions programmatically in JDBC

  1. Disable auto-commit: connection.setAutoCommit(false);
  2. Execute DML queries.
  3. Commit on success: connection.commit();
  4. Roll back on exception: connection.rollback();

What is Connection Pooling

Connection Pooling maintains a cache of pre-created, reusable physical database connections, eliminating the high latency of repeatedly opening and closing TCP socket database handshakes for every user request.

The three tiers in MVC (Model-View-Controller) Architecture

  • Model: Represents business data, entities, and database logic.
  • View: Generates presentation/UI displayed to the client (HTML, JSP, React).
  • Controller: Intercepts client requests, updates Model, and picks next View.

What is PDO in PHP and why is it preferred over mysqli

PDO (PHP Data Objects) provides a uniform, database-agnostic data access abstraction layer supporting 12+ relational database systems, whereas mysqli only works with MySQL.

What is an ORM (Object-Relational Mapping)

An ORM (e.g., Hibernate, JPA, Doctrine) automatically maps object-oriented classes and properties to relational database tables and foreign keys, abstracting raw SQL queries.

Conceptual & Architectural Analysis

Compare the 4 Types of JDBC Drivers with an Architecture Diagram

System Architecture / Concept DiagramHorizontal Scroll Enabled
+-------------------------------------------------------------+
| Type 1: JDBC-ODBC Bridge   | Java App -> JDBC -> ODBC -> DB |
| Type 2: Native-API Driver  | Java App -> JDBC -> C/C++ API  |
| Type 3: Network Protocol   | Java App -> Middleware Server  |
| Type 4: Pure Java Thin     | Java App -> Direct TCP/IP -> DB|
+-------------------------------------------------------------+
Driver TypePure Java?Client Installation Required?Performance
Type 1NoRequires native ODBC driverSlowest
Type 2NoRequires native vendor client libraryModerate
Type 3YesNo client installationGood
Type 4YesNo client installation (Direct socket)Fastest & Preferred

The 5 Standard Steps to Execute a Query in JDBC

5-Step JDBC Execution Lifecycle

  1. Load Driver Class: Class.forName("com.mysql.cj.jdbc.Driver"); (Modern JDBC 4.0 does this automatically via DriverManager SPI).
  2. Establish Connection: Connection conn = DriverManager.getConnection(url, user, pass);
  3. Create Statement: PreparedStatement ps = conn.prepareStatement("SELECT * FROM users WHERE id = ?");
  4. Execute Query: ResultSet rs = ps.executeQuery(); or int rows = ps.executeUpdate();
  5. Close Resources: Close ResultSet, Statement, and Connection (or use try-with-resources).

Transaction Management in JDBC with Rollback

Java
1Connection conn = null;
2try {
3 conn = dataSource.getConnection();
4 conn.setAutoCommit(false); // Begin Transaction
5
6 // Debit Account A
7 PreparedStatement psDebit = conn.prepareStatement("UPDATE accounts SET balance = balance - ? WHERE id = ?");
8 psDebit.setDouble(1, 5000.0);
9 psDebit.setInt(2, 101);
10 psDebit.executeUpdate();
11
12 // Credit Account B
13 PreparedStatement psCredit = conn.prepareStatement("UPDATE accounts SET balance = balance + ? WHERE id = ?");
14 psCredit.setDouble(1, 5000.0);
15 psCredit.setInt(2, 202);
16 psCredit.executeUpdate();
17
18 conn.commit(); // Commit Transaction
19 System.out.println("Transfer successful!");
20} catch (SQLException e) {
21 if (conn != null) conn.rollback(); // Rollback on failure!
22 System.err.println("Transaction rolled back: " + e.getMessage());
23} finally {
24 if (conn != null) conn.setAutoCommit(true);
25}

The MVC (Model-View-Controller) Flow in Web Applications

System Architecture / Concept DiagramHorizontal Scroll Enabled
                      [ Client Browser ]
                        |          ^
         1. HTTP Request|          | 6. Rendered HTML View
                        v          |
                 [ CONTROLLER (Servlet) ]
                   |               ^
         2. Updates|               | 5. Selects View & passes Data
                   v               |
            [ MODEL (JavaBean) ]   [ VIEW (JSP) ]
                   |                     ^
         3. SQL    |                     | 4. Reads Model
                   v                     |
            [ DATABASE ] ----------------+

Database Metadata in JDBC (DatabaseMetaData and ResultSetMetaData)

  • `DatabaseMetaData`: Obtains comprehensive information about the database software itself (product name, version, driver name, list of tables, supported SQL dialects).
  • `ResultSetMetaData`: Obtains schema information about the returned query columns (column count, column names, column data types, nullability).

In-Depth Analysis & Implementation

Develop a Complete Enterprise JDBC Data Access Object (DAO) Pattern Implementation with PreparedStatement and Connection Pooling

System Architecture / Concept DiagramHorizontal Scroll Enabled
package com.mjpru.bca.dao;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

// Student Entity Model
class Student {
    private int rollNo;
    private String name;
    private double marks;

    public Student(int rollNo, String name, double marks) {
        this.rollNo = rollNo;
        this.name = name;
        this.marks = marks;
    }
    public int getRollNo() { return rollNo; }
    public String getName() { return name; }
    public double getMarks() { return marks; }
}

// DAO Interface
interface StudentDAO {
    void addStudent(Student s) throws SQLException;
    Student getStudentByRoll(int rollNo) throws SQLException;
    List<Student> getAllStudents() throws SQLException;
}

// DAO Implementation
public class StudentDAOImpl implements StudentDAO {
    private final String jdbcURL = "jdbc:mysql://localhost:3306/mjpru_exam";
    private final String jdbcUser = "bca_admin";
    private final String jdbcPass = "exam2025";

    private Connection getConnection() throws SQLException {
        return DriverManager.getConnection(jdbcURL, jdbcUser, jdbcPass);
    }

    @Override
    public void addStudent(Student s) throws SQLException {
        String sql = "INSERT INTO students (roll_no, name, marks) VALUES (?, ?, ?)";
        try (Connection conn = getConnection();
             PreparedStatement ps = conn.prepareStatement(sql)) {
            ps.setInt(1, s.getRollNo());
            ps.setString(2, s.getName());
            ps.setDouble(3, s.getMarks());
            ps.executeUpdate();
            System.out.println("Student inserted successfully: " + s.getName());
        }
    }

    @Override
    public Student getStudentByRoll(int rollNo) throws SQLException {
        String sql = "SELECT roll_no, name, marks FROM students WHERE roll_no = ?";
        try (Connection conn = getConnection();
             PreparedStatement ps = conn.prepareStatement(sql)) {
            ps.setInt(1, rollNo);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    return new Student(rs.getInt("roll_no"), rs.getString("name"), rs.getDouble("marks"));
                }
            }
        }
        return null; // Not found
    }

    @Override
    public List<Student> getAllStudents() throws SQLException {
        List<Student> list = new ArrayList<>();
        String sql = "SELECT roll_no, name, marks FROM students ORDER BY roll_no ASC";
        try (Connection conn = getConnection();
             Statement stmt = conn.createStatement();
             ResultSet rs = stmt.executeQuery(sql)) {
            while (rs.next()) {
                list.add(new Student(rs.getInt("roll_no"), rs.getString("name"), rs.getDouble("marks")));
            }
        }
        return list;
    }
}

Database Connection Pooling Architecture and Compare HikariCP vs Traditional DriverManager

Connection Pooling vs DriverManager Architecture

System Architecture / Concept DiagramHorizontal Scroll Enabled
[ TRADITIONAL DriverManager ]
Request 1 ---> Open Socket -> DB Handshake -> Auth -> Run SQL -> Close Socket (HIGH LATENCY!)
Request 2 ---> Open Socket -> DB Handshake -> Auth -> Run SQL -> Close Socket (HIGH LATENCY!)

[ CONNECTION POOLING (HikariCP / DBCP) ]
Initial Startup: Pre-allocates 10-50 physical persistent TCP connections to DB
Request 1 ---> Borrow Connection from Pool -> Run SQL -> Return to Pool (LOW LATENCY! <1ms)
Request 2 ---> Borrow Connection from Pool -> Run SQL -> Return to Pool

Why HikariCP Outperforms Others:

  1. Bytecode Engineering: Extremely lean assembly and bytecode optimization.
  2. Zero Overhead: Eliminates lock contention via lock-free collections (FastList, ConcurrentBag).
  3. Thread Safety: Prevents connection leakage and connection stall through rigorous timeouts (connectionTimeout, idleTimeout, maxLifetime).

The Complete MVC Web Architecture with a Working End-to-End Case Study in Java Servlets and JSP

Enterprise MVC Case Study

1. Model: StudentBean.java

Represents state and database records with getter/setter properties.

2. Controller: StudentControllerServlet.java

  • Intercepts requests like /students?action=list.
  • Calls StudentDAO to retrieve list of student objects.
  • Places student list into request scope: request.setAttribute("studentList", list);.
  • Dispatches to View: request.getRequestDispatcher("student_view.jsp").forward(request, response);.

3. View: student_view.jsp

  • Uses JSTL <c:forEach> to loop through ${studentList} and render formatted HTML tables.
  • Contains zero business or database code, guaranteeing clean separation of concerns and maintainability.

Important Exam Points & Quick Revision

Examiner high-yield focus: 4 types of JDBC drivers, Statement vs PreparedStatement, and DAO Pattern with Transaction rollback.

Your reading progress
0%

100% left on this page — finishing it closes the gap for Database Access with JDBC, PHP-MySQL & MVC Frameworks.

Weak topic hint

Database Access with JDBC, PHP-MySQL & MVC Frameworks still counts as a weak topic until you finish this note and answer its questions.

Practise this unit
What Should You Do Next?

Test Your Understanding

Now that you've read through these notes, practice unit MCQs to identify weak points and solidify your learning before exams.