From 23d935f1c1513d546005111e4281978395d00059 Mon Sep 17 00:00:00 2001 From: abdul Date: Fri, 20 Feb 2026 15:11:22 +0000 Subject: [PATCH] Ajouter main.cpp --- main.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 main.cpp diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e071303 --- /dev/null +++ b/main.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include +#include "User.h" + +using namespace std; +int main() { + try { + sql::mysql::MySQL_Driver *driver; + sql::Connection *con; + + driver = sql::mysql::get_mysql_driver_instance(); + // Connexion à XAMPP + con = driver->connect("tcp://127.0.0.1:3306", "root", ""); + con->setSchema("university_db"); + + std::cout << "SUCCESS: Connexion etablie avec XAMPP !" << std::endl; + + sql::Statement *stmt = con->createStatement(); + sql::ResultSet *res = stmt->executeQuery("SELECT username FROM users"); + + while (res->next()) { + std::cout << "Utilisateur trouve dans la base : " << res->getString("username") << std::endl; + } + + delete res; + delete stmt; + delete con; + + } catch (sql::SQLException &e) { + std::cout << "ERREUR SQL : " << e.what() << std::endl; + } + + return 0; +} \ No newline at end of file