MySQL Forums
Forum List  »  Connector/C++

Eclipse program crashing when connecting to MySQL Server
Posted by: Michael Varghese Thomas
Date: January 28, 2018 10:46PM

I am writing a simple program in Eclipse CDT to connect to a MySQL Server hosted locally. I have ensured the server is running. The code I am trying to execute is the following:

  void CMyClass::fnDatabaseConnection(){

  sql::Driver *driver;
  sql::Connection *connection;
  sql::ResultSet *result;
  sql::Statement *statement;
  sql::PreparedStatement *prepared;
  driver = get_driver_instance();

  connection = driver->connect("tcp://127.0.0.1:3306","DBServer","root"); /*Where the program crashes*/

  statement = connection->createStatement();
  statement->execute("SHOW DATABASES");

  delete statement;
  delete connection;
}

The include statements are:

#include <mysql_driver.h>
#include <mysql_connection.h>
#include <stdlib.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

The program crashes on running. While debugging I can see that the crash occurs while trying to establish the connection to the server. I have ensured that all required libraries have been added along with the required include files (I have images for the same but am unable to add them here). I am not sure what is it that I am doing wrong.

One of my doubts is the get_driver_instance() function used might from a different library, but adding sql:: or even sql::mysql:: in front of it gives undefined reference errors, even though the libraries have been added.

Here are items that have been included:
[output]
Header Files:
-I
1. "C:\Program Files\MySQL\MySQL Server 5.6\include"
2. "C:\Program Files\MySQL\Connector.C++ 1.1\include"
3. "C:\boost_1_66_0"

-include
1. "C:\Program Files\MySQL\Connector.C++ 1.1\include\mysql_connection.h" (added manually as there was an issue with the compiler finding it)

Libraries:
-L
1. "C:\Program Files\MySQL\MySQL Server 5.6\lib"
2. "C:\Program Files\MySQL\Connector.C++ 1.1\lib\opt"

Miscellaneous ( as they don't follow GCC naming conventions)
1. "C:\Program Files\MySQL\Connector.C++ 1.1\lib\opt\mysqlcppconn-static.lib"
2. "C:\Program Files\MySQL\Connector.C++ 1.1\lib\opt\mysqlcppconn.dll"
3. "C:\Program Files\MySQL\MySQL Server 5.6\lib\mysqlclient.lib"
4. "C:\Program Files\MySQL\MySQL Server 5.6\lib\libmysql.lib"
[/output]

Options: ReplyQuote


Subject
Views
Written By
Posted
Eclipse program crashing when connecting to MySQL Server
823
January 28, 2018 10:46PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.