Module 16: JDBC

Markdown

View as Markdown

Module Overview

This module introduces Java Database Connectivity (JDBC), which allows Java applications to communicate with relational databases.

Learners will understand the purpose of JDBC, explore different JDBC drivers and learn how to establish a connection between Java applications and MySQL databases.

The module also covers essential database operations, including inserting, selecting, updating and deleting records.

Learners will work with PreparedStatement to execute parameterised SQL queries and manage database information through Java programs.

These concepts help learners understand how database-driven applications store, retrieve and manage business information.

What Will Be Covered

16.1 What is JDBC?

  • Understanding the meaning and purpose of Java Database Connectivity (JDBC).

  • Exploring how JDBC connects Java applications with databases.

  • Understanding the role of JDBC APIs.

  • Exploring the JDBC architecture.

  • Understanding how Java applications communicate with database systems.

  • Identifying the components involved in JDBC-based database operations.

16.2 JDBC Drivers

  • Understanding the purpose of JDBC drivers.

  • Exploring how JDBC drivers enable database communication.

  • Understanding the different types of JDBC drivers.

  • Learning how JDBC drivers work with the JDBC DriverManager.

  • Understanding driver configuration requirements.

  • Identifying suitable drivers for connecting Java applications with databases.

16.3 Connecting Java with MySQL

  • Understanding the requirements for connecting Java applications with MySQL.

  • Setting up the MySQL database connection.

  • Loading and registering the JDBC driver.

  • Establishing database connections using DriverManager.

  • Understanding connection strings and database credentials.

  • Working with Connection objects.

  • Handling connection-related exceptions.

  • Closing database connections after operations.

16.4 Insert Data

  • Understanding how Java applications insert records into MySQL tables.

  • Writing INSERT SQL statements.

  • Creating SQL execution statements.

  • Passing values from Java programs to database queries.

  • Executing insert operations.

  • Verifying successfully inserted records.

  • Applying insert operations to manage business information.

16.5 Select Data

  • Understanding how to retrieve records from MySQL databases.

  • Writing SELECT SQL statements.

  • Executing queries through JDBC.

  • Working with ResultSet objects.

  • Retrieving individual column values.

  • Processing multiple records returned by a query.

  • Displaying database information through Java applications.

16.6 Update Data

  • Understanding how Java applications modify existing database records.

  • Writing UPDATE SQL statements.

  • Identifying records using WHERE conditions.

  • Executing update operations through JDBC.

  • Understanding the number of affected records.

  • Verifying updated information.

  • Applying update operations to maintain accurate business records.

16.7 Delete Data

  • Understanding how to remove records from MySQL databases.

  • Writing DELETE SQL statements.

  • Identifying records using appropriate conditions.

  • Executing delete operations through JDBC.

  • Understanding the impact of deleting database records.

  • Verifying deletion results.

  • Applying delete operations to manage outdated or unnecessary records.

16.8 PreparedStatement

  • Understanding the purpose of PreparedStatement in JDBC.

  • Creating parameterised SQL statements.

  • Setting query parameters using methods such as setString() and setInt().

  • Executing parameterised INSERT, SELECT, UPDATE and DELETE operations.

  • Understanding how PreparedStatement handles query parameters.

  • Exploring the benefits of prepared statements for repeated query execution.

  • Understanding how parameterised queries help reduce SQL injection risks.

Skills You Will Gain

  • Understanding JDBC architecture and database connectivity.

  • Identifying and working with JDBC drivers.

  • Establishing connections between Java and MySQL.

  • Executing SQL statements through Java applications.

  • Inserting records into database tables.

  • Retrieving and processing database records.

  • Updating existing database information.

  • Deleting records through Java programs.

  • Working with Connection, Statement and ResultSet objects.

  • Creating and executing parameterised queries using PreparedStatement.

  • Managing database connections and related exceptions.

Learning Outcomes

By the end of this module, learners will be able to:

  • Explain how JDBC enables Java applications to communicate with relational databases.

  • Configure JDBC drivers and establish connections to MySQL databases.

  • Develop Java application functionality to store business information in database tables.

  • Retrieve customer, employee, product and transaction records using SQL queries.

  • Update existing records to maintain accurate application information.

  • Delete records based on defined business requirements.

  • Use PreparedStatement to execute parameterised queries and handle user-provided data more safely.

  • Process database query results using ResultSet.

  • Build Java applications that interact with MySQL for storing, retrieving and managing business information.

Certification Alignment

This module develops Java database connectivity knowledge that supports the broader learning pathway towards the Oracle Certified Professional: Java SE 17 Developer certification.

The topics covered help learners understand JDBC architecture, database drivers, SQL operations, connection management and parameterised queries within Java applications.

Continue to the Next Module

Continue to Module 17: GUI Programming to learn how to develop graphical user interfaces using Java Swing, work with JFrame, JLabel, JButton, JTextField, JCheckBox and JTable, and handle user interactions through event handling.

Was this article helpful?

Still need help?

Contact us