The download package contains usage examples in the directory
examples/
. The examples explain the basic
usage of the following classes:
Connection
Driver
PreparedStatement
ResultSet
ResultSetMetaData
Statement
The examples cover:
Using the
Driver
class to connect to MySQLCreating 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
The examples in this document are only code snippets. The code
snippets provide a brief overview on the API. They are not
complete programs. Please check the examples/
directory of your MySQL Connector/C++ installation for complete programs.
Please also read the README
file in the
examples/
directory. Note to test the example
code you will first need to edit the
examples.h
file in the
examples/
directory, to add your connection
information. Then simply rebuild the code by issuing a
make
command.
The examples in the examples/
directory
include:
examples/connect.cpp
:How to create a connection, insert data into MySQL and handle exceptions.
examples/connection_meta_schemaobj.cpp
:How to obtain metadata associated with a connection object, for example, a list of tables, databases, MySQL version, connector version.
examples/debug_output.cpp
:How to activate and deactivate the MySQL Connector/C++ debug protocol.
examples/exceptions.cpp
:A closer look at the exceptions thrown by the connector and how to fetch error information.
examples/prepared_statements.cpp
:How to run Prepared Statements including an example how to handle SQL commands that cannot be prepared by the MySQL Server.
examples/resultset.cpp
:How to fetch data and iterate over the result set (cursor).
examples/resultset_meta.cpp
:How to obtain metadata associated with a result set, for example, number of columns and column types.
examples/resultset_types.cpp
:Result sets returned from metadata methods - this is more a test than much of an example.
examples/standalone_example.cpp
:Simple standalone program not integrated into regular CMake builds.
examples/statements.cpp
:How to run SQL commands without using Prepared Statements.
examples/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.