Documentation Home
MySQL Connector/C++ Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 0.7Mb
PDF (A4) - 0.7Mb
EPUB - 0.7Mb
HTML Download (TGZ) - 0.6Mb
HTML Download (Zip) - 0.7Mb


MySQL Connector/C++ Developer Guide  /  Getting Started with Connector/C++: Usage Examples

Chapter 7 Getting Started with Connector/C++: Usage Examples

Source distributions of Connector/C++ include an examples directory that contains usage examples that explain how to use the following classes:

  • Connection

  • Driver

  • PreparedStatement

  • ResultSet

  • ResultSetMetaData

  • Statement

The examples cover:

  • Using the Driver class to connect to MySQL

  • Creating tables, inserting rows, fetching rows using (simple) statements

  • Creating tables, inserting rows, fetching rows using prepared statements

  • Hints for working around prepared statement limitations

  • Accessing result set metadata

Several examples in this document are only code snippets, not complete programs. These snippets provide a brief overview on the API. For complete programs, check the examples directory of your Connector/C++ installation Please also read the README file in that directory. To test the example code, edit the examples.h file in the examples directory to add your connection information, then rebuild the code by issuing a make command.

The example programs in the examples directory include:

  • connect.cpp:

    How to create a connection, insert data, and handle exceptions.

  • connection_meta_schemaobj.cpp:

    How to obtain metadata associated with a connection object, such as a list of tables or databases, the MySQL version, or the connector version.

  • debug_output.cpp:

    How to activate and deactivate the Connector/C++ debug protocol.

  • exceptions.cpp:

    A closer look at the exceptions thrown by the connector and how to fetch error information.

  • prepared_statements.cpp:

    How to execute Prepared Statements, including an example showing how to handle SQL statements that cannot be prepared by the MySQL Server.

  • resultset.cpp:

    How to use a cursor to fetch data and iterate over a result set.

  • resultset_meta.cpp:

    How to obtain metadata associated with a result set, such as the number of columns and column types.

  • resultset_types.cpp:

    Result sets returned from metadata methods. (This is more a test than an example.)

  • standalone_example.cpp:

    Simple standalone program not integrated into regular CMake builds.

  • statements.cpp:

    How to execute SQL statements without using Prepared Statements.

  • cpp_trace_analyzer.cpp:

    This example shows how to filter the output of the debug trace. Please see the inline comments for further documentation. This script is unsupported.


User Comments
Sign Up Login You must be logged in to post a comment.