简体   繁体   中英

MariaDB connector c ++ memory protection violation

I am having a problem connecting to the database using MariaDB. When I try to do anything with conn, it prints a memory violation. I use Linux Mint 20.1!!

#include <iostream>
#include <memory>
#include <mariadb/conncpp.hpp>

int main(int argc, char**argv)
{
      sql::Driver* driver = sql::mariadb::get_driver_instance();

      sql::SQLString url("///");
      sql::SQLString base("///");
      std::cout << driver->getName() << std::endl;
      sql::Properties properties({
            {"base", "base"},
            {"password", "password"}
         });

      sql::Connection*conn = driver->connect(url,properties);
      conn->setSchema(base);// here
}

Does anyone know what the problem is? Thank you in advance for your help.

driver->connect may return nullptr. I guess that is happening. You don't check conn. There is also DriverManager::getConnection, that unlike Driver::connect will throw an exception in such case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM