Goals

Learn how to connect an application to a database using frameworks, drivers, and libraries. Understand how connection pools are used to process parallel requests to a database, and how environments distinguish different modes of operation. Use parametrized queries to prevent injection attacks and prepared statements to improve security and performance. Finally, implement a task tracker using multiple programming languages.

Examples

Exercises

Introduction

Context

Three-tiered Architecture

A server can also act as a client to another server. For instance, web servers frequently store data in a database server and, as a result, function as clients of the database server. This design is known as a three-tiered architecture and is quite common in typical web applications. The term was originally coined by John J. Donovan, who described them as presentation tier, logic tier and data tier - browser, web server and database.

tanenbaum_three_tiered_architecture.svg

Database Connectivity

Access a relational database from an application

Installation and Setup

Application servers can be implemented in a variety of programming languages. Each language handles database access a little bit different, but the fundamental steps are the same.

1. Find Database Driver Find and install a suitable database driver
2. Setup Connection Using the driver, setup a connection to the database
3. Execute Queries Create and setup SQL queries and send them using the connection
4. Parse Results Use the response data in your application

Frameworks, Drivers and Libraries

Frameworks

Many languages offer frameworks that implement access to databases:

Java JDBC API

sql package - database/sql - Go Packages

SQLx — db interface for Rust

Home | SQLAPI++

Drivers