I'm trying to execute a very basic MySQL statement in C++ using MySQL Connector/C++. Unfortunately, my very basic code is failing in a way that has stumped me. Here is the code that I have:
try
{
sql::mysql::MySQL_Driver *driver = NULL;
sql::Connection *conn = NULL;
sql::Statement *stmt = NULL;
driver = sql::mysql::get_mysql_driver_instance();
if (driver != NULL)
{
conn = driver->connect("127.0.0.1:3306", "root", "root");
cout << "Test" << endl;
stmt = conn->createStatement();
stmt->execute("USE mysql");
}
delete conn;
conn = NULL;
}
This code fails with an error that says "My SQL server has gone away". I've read that this error occurs because of a timeout after something like an hour, but this is happening immediately when I execute the program. Any ideas on how I can fix this issue?