Actually:
DO NOT USE: sql::Driver::threadInit() and sql::Driver::threadEnd()
BECAUSE: you are already using try()
YOU FORGOT:
res->close(); stmt->close(); con->close(); delete res; delete stmt; delete con;
EXAMPLE:
int connection_and_query_func() { sql::Driver *driver; sql::Connection *con; sql::Statement *stmt; sql::ResultSet *res; int err_exception_getErrorCode=0; int my_int_from_column_1 = 0; double my_double_from_column_2 = 0; .... std:string my_string_from_column_p = ""; try { driver = get_driver_instance(); con = driver->connect("address_name", "user_name", "password"); con->setSchema("schema_name"); stmt = con->createStatement(); res = stmt->executeQuery("your query statement here"); my_int_from_column_1 = res->getInt(1); my_double_from_column_2 = res->getDouble(2); .... my_string_from_column_p = res->getString(p); res->close(); stmt->close(); con->close(); delete res; delete stmt; delete con; }; catch (sql::SQLException &exception) { err_exception_getErrorCode = exception.getErrorCode(); }; return(0); };
CONCLUSION: this can be done as many times as you want. An example function (connection_and_query_func ()) will close the MySQL connection properly after it is completed - without adding processes to your MySQL server !!!
FURTHERMORE: read the official guide https://docs.oracle.com/cd/E17952_01/connector-cpp-en/connector-cpp-en.pdf
ALTERNATIVE: if you cannot properly close your connection and request a program / function from your side (thus compiling processes to your MySQL server), consider the following two options:
1 / Set all MySQL timeout parameters to 10 seconds. or less (for example); 2 / write a script that says SHOW PROCESSLIST and delete processes that are in SLEEP for too long.
Greetings.
source share