Eclipse program crashing when connecting to MySQL Server

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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:

1
2
3
4
5
6
7
8
#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:

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"
Last edited on
Before using driver,connection and statement you should check that they are not nullptr.
Also try to wrap the code into a try catch block to see if you get an error msg.
I have checked this for the driver variable and it is not a null ptr. When I try to use an SQLException to catch an exception as follows:
1
2
3
4
5
6
try{
	connection = driver->connect(ip,user,password);
}
catch(sql::SQLException e){
		cout<<"Error";
}


I get the following error:

undefined reference to `_imp___ZTVN3sql12SQLExceptionE'	SlaveController		line 65, external location: C:\Program Files\MySQL\Connector.C++ 1.1\include\cppconn\exception.h


If this is a library issue, should it not have raised an error when I created a driver object?

PS: The driver value is 0x2d18b0. I printed it out to check if it was null.
Topic archived. No new replies allowed.