Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
2
Indexable
Never
#include <mysql_driver.h>
#include <mysql_connection.h>
#include <cppconn/statement.h>
#include <cppconn/resultset.h>

int main() {
    sql::mysql::MySQL_Driver* driver;
    sql::Connection* con;

    driver = sql::mysql::get_mysql_driver_instance();
    con = driver->connect("tcp://127.0.0.1:3306", "username", "password"); // Замените "username" и "password" на ваши реальные данные
    con->setSchema("testdb"); // Замените "testdb" на имя вашей базы данных

    sql::Statement* stmt;
    sql::ResultSet* res;

    stmt = con->createStatement();
    res = stmt->executeQuery("SELECT * FROM games");

    while (res->next()) {
        std::cout << "id: " << res->getInt("id") << std::endl;
        std::cout << "title: " << res->getString("title") << std::endl;
        std::cout << "genre: " << res->getString("genre") << std::endl;
        std::cout << "release_date: " << res->getString("release_date") << std::endl;
        std::cout << "price: " << res->getDouble("price") << std::endl;
        std::cout << std::endl;
    }

    delete res;
    delete stmt;
    delete con;

    return 0;
}