Problem mit MySQL-Verbindung
-
Hey Leute,
wie schon im Titel geschrieben, habe ich Probleme eine Verbindung zu MySQL aufzubauen.
Den Quellcode habe ich aus einem Tutorial und ich habe echt keine Ahnung wie ich die Fehlermeldung beheben kann.#include "stdafx.h" #include <stdlib.h> #include <iostream> #include <sstream> #include <stdexcept> #include "mysql_connection.h" #include <cppconn/driver.h> #include <cppconn/exception.h> #include <cppconn/resultset.h> #include <cppconn/statement.h> #include <cppconn/prepared_statement.h> #define EXAMPLE_HOST "localhost" #define EXAMPLE_USER "root" #define EXAMPLE_PASS "" #define EXAMPLE_DB "world" using namespace std; int main(int argc, const char **argv) { string url(argc >= 2 ? argv[1] : EXAMPLE_HOST); const string user(argc >= 3 ? argv[2] : EXAMPLE_USER); const string pass(argc >= 4 ? argv[3] : EXAMPLE_PASS); const string database(argc >= 5 ? argv[4] : EXAMPLE_DB); cout << "Connector/C++ tutorial framework..." << endl; cout << endl; try { /* INSERT TUTORIAL CODE HERE! */ sql::Driver *driver; sql::Connection *con; sql::Statement *stmt; sql::ResultSet *res; /* Create a connection */ driver = get_driver_instance(); con = driver->connect("tcp://127.0.0.1:3306", "root", "1234"); /* Connect to the MySQL test database */ con->setSchema("test"); } catch (sql::SQLException &e) { /* The MySQL Connector/C++ throws three different exceptions: - sql::MethodNotImplementedException (derived from sql::SQLException) - sql::InvalidArgumentException (derived from sql::SQLException) - sql::SQLException (derived from std::runtime_error) */ cout << "# ERR: SQLException in " << __FILE__; cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl; /* Use what() (derived from std::runtime_error) to fetch the error message */ cout << "# ERR: " << e.what(); cout << " (MySQL error code: " << e.getErrorCode(); cout << ", SQLState: " << e.getSQLState() << " )" << endl; return EXIT_FAILURE; } cout << "Done." << endl; system("PAUSE"); return EXIT_SUCCESS; }"Unbehandelte Ausnahme bei 0x733db9f0 in connecttobumsdeinemudder.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x00000020."
Das ist die Fehlermeldung und Visual zeigt mir, dass sie in diesercon = driver->connect("tcp://127.0.0.1:3306", "root", "1234");Zeile auftaucht.
Ich hoffe ihr könnt mir helfen.
Vielen Dank schon mal im Voraus dafür, dass ihr in den Thread geguckt habt
lg
-
Hat sich erledigt.
