Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "DBConnectionManager.h"
- using namespace std;
- DBConnectionManager::DBConnectionManager() {
- cout << "Starting DBConnectionManager - Updated" << endl;
- try {
- cout << "Getting driver instance" << endl;
- driver = get_driver_instance();
- cout << "Got driver instance" << endl;
- conn = driver->connect("tcp://127.0.0.1:3306", "root", "54mCuw901");
- conn->setSchema("bugs");
- cout << "Connected to database" << endl;
- }
- catch (SQLException ex) {
- cout << "Error connecting to DB: " << ex.what() << endl;
- }
- catch (...) {
- cout << "Something has gone wrong" << endl;
- }
- }
- #ifndef MYSQLTEST_DBCONNECTIONMANAGER_H
- #define MYSQLTEST_DBCONNECTIONMANAGER_H
- #include <driver.h>
- #include <exception.h>
- #include <resultset.h>
- #include <statement.h>
- using namespace sql;
- class DBConnectionManager
- {
- private:
- sql::Driver *driver;
- sql::Connection *conn;
- sql::Statement *statement;
- sql::ResultSet *res;
- public:
- DBConnectionManager();
- void performSql();
- };
- #endif //MYSQLTEST_DBCONNECTIONMANAGER_H
- cmake_minimum_required(VERSION 3.6)
- project(MySQLTest)
- include_directories("C:\Program Files\MySQL\MySQL Connector C++ 1.1.7\include\cppconn" "C:\Program Files\MySQL\MySQL Connector C++ 1.1.7\lib\opt")
- SET(GCC_COVERAGE_LINK_FLAGS "-m64 -Wl,--image-base -Wl,0x10000000 -lpthread -pthread")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -m64 -Wl,--image-base -Wl,0x10000000 -lpthread -pthread ")
- set(SOURCE_FILES main.cpp DBConnectionManager.cpp)
- add_executable(MySQLTest ${SOURCE_FILES})
- add_library(mysqlcppconn.lib)
- set_target_properties(MySQLTest PROPERTIES LINKER_LANGUAGE CXX)
- set_target_properties(mysqlcppconn.lib PROPERTIES LINKER_LANGUAGE CXX)
- target_link_libraries(MySQLTest "C:\Program Files\MySQL\MySQL Connector C++ 1.1.7\lib\opt\mysqlcppconn.lib")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement