Java · Advanced level

Advanced level · Module 3 of 6 · 24 guided hours

Databases with JDBC

Design a relational schema, access it from Java with JDBC and prepared statements, and keep data consistent with transactions.

Learning objectives

  • Write SQL to create, query and change relational data
  • Connect to a database from Java and run parameterised queries
  • Implement repositories with transactions and safe resource handling

Topics

  • tables, keys and relationships
  • SELECT, JOIN, GROUP BY
  • JDBC Connection and DriverManager
  • PreparedStatement and SQL injection
  • ResultSet mapping
  • transactions and rollback

Lessons

  1. Lesson 1 Relational Data and SQL for Java Developers

    Design tables with primary and foreign keys and write the SQL queries an application needs.

    primary keyforeign keyJOINGROUP BY

  2. Lesson 2 Connecting with JDBC

    Open database connections from Java, run queries with PreparedStatement and map results to objects.

    JDBC URL and driverConnectionPreparedStatementResultSet

  3. Lesson 3 Preventing SQL Injection

    Understand how SQL injection works and why parameterised queries prevent it.

    SQL injectionparameter bindingleast privilegeinput validation

  4. Lesson 4 Transactions and the Repository Layer

    Group related changes into transactions, roll back on failure and keep database code behind repository interfaces.

    transactioncommit and rollbackatomicityintegration test

Practical activity

Replace the CSV storage of the library project with a database-backed repository, keeping the service and its tests unchanged.

Expected outcomes

  • Safe, parameterised database access from Java
  • Repositories that keep data consistent

Assessment

Practical: implement a JDBC repository for a provided schema; marked by integration tests and a review for SQL-injection safety and closed resources.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.