# Application Development with MariaDB Connector/C++

MariaDB Connector/C++ enables C++ applications to establish client connections to MariaDB database products over TLS.

## Build Your Application with Connector/C++

When you build a C++ application, your compiler must link your application with the MariaDB Connector/C++ shared library.

The following g++ ([GNU GCC](https://gcc.gnu.org/)) command demonstrates how to link an application with the MariaDB Connector/C++ shared library using the -lmariadbcpp argument:

```bash
$ g++ -o example example.cpp -std=c++11 -lmariadbcpp
```

If you are not using the g++ compiler, please consult your compiler's manual.

## Header Files

MariaDB Connector/C++ includes several header files. In some cases, developers might find it useful to inspect the MariaDB Connector/C++ header files to view the definitions of classes, functions, and methods.

The header files:

* Contain the definitions of classes, functions, and methods in the `sql` namespace.
* Are installed to the `/usr/include/mariadb/conncpp/` directory by default on Linux.

C++ applications developed using MariaDB Connector/C++ must include the `conncpp.hpp` header file.

When a C++ application includes `conncpp.hpp`, the application will automatically include other header files that are included by `conncpp.hpp`:

* `CallableStatement.hpp`
* `Connection.hpp`
* `DatabaseMetaData.hpp`
* `Driver.hpp`
* `DriverManager.hpp`
* `Exception.hpp`
* `jdbccompat.hpp`
* `ParameterMetaData.hpp`
* `PreparedStatement.hpp`
* `ResultSet.hpp`
* `ResultSetMetaData.hpp`
* `Savepoint.hpp`
* `SQLString.hpp`
* `Statement.hpp`
* `Types.hpp`
* `Warning.hpp`

## Classes

MariaDB Connector/C++ implements many different classes.

Most C++ applications developed using MariaDB Connector/C++ will use some of the following classes:

| Class                  | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| sql::Connection        | Establish a connection to a MariaDB database product. A Connection can be closed by calling close(), or there is an implicit close when using a smart pointer.                                                                                                                                                                                                                                                                                                                                                                                               |
| sql::DatabaseMetaData  | Provides detailed information about the database metadata, such as database name, version, schemas, tables, columns, procedures, and support for various features.                                                                                                                                                                                                                                                                                                                                                                                           |
| sql::Driver            | Implements the non-static connect() method, which is a [connection method](/docs/connectors/mariadb-connector-cpp/connect-with-mariadb-connectorcpp.md).                                                                                                                                                                                                                                                                                                                                                                                                     |
| sql::DriverManager     | Implements the static getConnection() method, which is a [connection method](/docs/connectors/mariadb-connector-cpp/connect-with-mariadb-connectorcpp.md).                                                                                                                                                                                                                                                                                                                                                                                                   |
| sql::PreparedStatement | Execute a query that contains variable text. Prepared statements can be used to sanitize input. Therefore, using prepared statements reduces the risk of SQL injection attacks. A PreparedStatement can be closed by calling close(), or there is an implicit close when using a smart pointer. By default, the connector will use client-side prepared statements. To use server-side prepared statements, set the useServerPrepStmts [optional connection parameter](/docs/connectors/mariadb-connector-cpp/connect-with-mariadb-connectorcpp.md) to true. |
| sql::ResultSet         | Fetch query results. A ResultSet can be closed by calling close(), or there is an implicit close when using a smart pointer.                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| sql::ResultSetMetaData | Provides detailed information about a result set, such as schema name, table name, column names and types, and column attributes; whether a column is auto increment, and nullable.                                                                                                                                                                                                                                                                                                                                                                          |
| sql::Statement         | Execute a query that does not contain variable text. A Statement can be closed by calling close(), or there is an implicit close when using a smart pointer.                                                                                                                                                                                                                                                                                                                                                                                                 |

<sub>*This page is: Copyright © 2025 MariaDB. All rights reserved.*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/connectors/mariadb-connector-cpp/application-development-with-mariadb-connector-cpp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
