MariaDB Connector/C++ Sample Application

Tasks.cpp is a complete sample application that demonstrates CRUD (Create, Read, Update, Delete) operations using the MariaDB Connector/C++.

Setup

The tasks.cpp sample application depends on a database, todo and the table task.,

Create the example database and table:

CREATE DATABASE IF NOT EXISTS todo;

CREATE TABLE todo. tasks (
   id INT AUTO_INCREMENT PRIMARY KEY,
   description VARCHAR(200),
   completed BOOLEAN DEFAULT FALSE);

Create a user db_user with privileges to execute the tasks of the sample application:

CREATE USER IF NOT EXISTS db_user@192.0.2.1
   IDENTIFIED BY 'db_user_password';

GRANT ALL PRIVILEGES ON todo.* TO db_user@192.0.2.1;

Within the tasks.cpp file, navigate to the main method, and add the database connection values:

sql::SQLString url("jdbc:mariadb://192.0.2.1:3306/todo");
sql::Properties properties({{"user", "db_user"}, {"password", "db_user_password"}});

Compiling

After adding the connection details to the tasks.cpp file, build the sample application:

Usage

The sample application supports CRUD (Create, Read, Update, Delete) operations.

Create

Create a new task record:

Read

Read all task records:

If the task got added, the preceding command lists the task:

Update

Update an existing task record:

If the task got updated, the ./tasks showTasks command lists the updated task:

Delete

Delete a task record:

This page is: Copyright © 2025 MariaDB. All rights reserved.

Last updated

Was this helpful?