Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Need tutorial on how to set up and use MySql Connector/C++ in eclipse on my M1 Macbook(How do I get eclipse on my M1 Macbook work with MySql Connector/C++)
Need tutorial on how to set up and use MySql Connector/C++ in eclipse on my M1 Macbook [message #1862531] Sat, 09 December 2023 15:54
Eclipse UserFriend
I have downloaded
mysql-connector-c++-8.2.0-macos13-arm64
and I am using
Eclipse IDE for C/C++ Developers (includes Incubating components)

Version: 2023-12 (4.30.0)
Build id: 20231201-2043

I made a new C++ project and have tried both
Cross GCC
and
MacOSX GCC

I put the path to the include directory
/Users/me/c++Libraries/mysql-connector-c++-8.2.0-macos13-arm64/include/mysql
In the C/C++ General > Path and Symbols

Then I tried to do a simple program to connect to my local MySql database using the following... and I get errors saying it cant resolve the header files.

/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>

/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/

/* None of these header files will it locate */
#include <mysql.h>
#include <mysqlx/xdevapi.h>
#include "mysql_connection.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

using namespace std;

int main(void)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' »
AS _message'..." << endl;

try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;

/* Create a connection */
/* IT ERRORS ON THIS LINE COULD NOT BE RESOLVED */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");

stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
cout << res->getString("_message") << endl;
cout << "\t... MySQL says it again: ";
/* Access column data by numeric offset, 1 is the first column */
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete con;

} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " »
<< __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}

cout << endl;

return EXIT_SUCCESS;
}
Previous Topic:can't format c++ code
Next Topic:Attempting to set up C environment in Eclipse & getting "Content is not in prolog" err
Goto Forum:
  


Current Time: Wed Feb 19 03:02:19 GMT 2025

Powered by FUDForum. Page generated in 0.03197 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top