# Working with Data

Most Java applications are driven by data. This means that we need our applications to connect to a database to save or retrieve data.

Updated: November 16, 2026

## [Configure the Project](https://www.ask-codey.com/courses/java-full-stack-bootcamp/topics/configure-the-project)

1. [Configure the Project](https://www.ask-codey.com/lessons/configure-the-project) (Journeyman): Add the MySQL driver, commons-dbcp2 and spring-jdbc dependencies to a Maven project's pom.xml so your Java code can work with a MySQL database.

## [Querying a Database](https://www.ask-codey.com/courses/java-full-stack-bootcamp/topics/querying-a-database)

1. [Querying a Database: an overview](https://www.ask-codey.com/lessons/querying-a-database-an-overview) (Journeyman): Reading data from a database in Java takes three steps: connect to the database, run an SQL query, and read the results.
2. [JDBC Objects](https://www.ask-codey.com/lessons/querying-a-database-jdbc-objects) (Journeyman): Meet the three objects that query MySQL from Java: a BasicDataSource to connect, a JdbcTemplate to run SQL, and a SqlRowSet to read the rows that come back.
3. [Full Example](https://www.ask-codey.com/lessons/querying-a-database-full-example) (Journeyman): A complete main method that connects to the northwind database, selects every product, and prints each product's id, name and price.

## [Working with User Input](https://www.ask-codey.com/courses/java-full-stack-bootcamp/topics/working-with-user-input)

1. [Working with User Input](https://www.ask-codey.com/lessons/working-with-user-input) (Journeyman): Pass user input to a query as a ? parameter instead of joining it into the SQL string, so nobody can run a SQL injection attack on your database.

## [Mapping Data to Models](https://www.ask-codey.com/courses/java-full-stack-bootcamp/topics/mapping-data-to-models)

1. [Mapping Data to Models: an overview](https://www.ask-codey.com/lessons/mapping-data-to-models-an-overview) (Journeyman): Storing query results in model objects lets your program reuse the data without querying the database again.
2. [Model Review](https://www.ask-codey.com/lessons/mapping-data-to-models-model-review) (Journeyman): A Category model class has a private field, a getter and a setter for each column of the categories table.
3. [Mapping Data to Models](https://www.ask-codey.com/lessons/mapping-data-to-models) (Journeyman): Turn each row of a query result into a Category object and collect them in an ArrayList.
4. [Data Access Objects](https://www.ask-codey.com/lessons/mapping-data-to-models-data-access-objects) (Journeyman): A data access object (DAO) is a class that holds the database code for one table, so the rest of your program calls methods like getAllCategories() instead of writing SQL.
5. [Example](https://www.ask-codey.com/lessons/mapping-data-to-models-example) (Journeyman): A CategoriesDao class loads every category from the database into a list, and Main prints each category's name.

Source: https://www.ask-codey.com/courses/java-full-stack-bootcamp/chapters/working-with-data
