Why is std::bad_alloc thrown by get_driver_instance()?

3

I'm trying to run a C++ MySQL example from the mysql.com website.

#define DBHOST "tcp://127.0.0.1:3306/"
#define USER "root"
#define PASSWORD ""

//...

string url(DBHOST);
const string user(USER);
const string password(PASSWORD);
const string database(DATABASE);

try {
    driver = sql::mysql::get_driver_instance();

    /* create a database connection using the Driver */

    con = driver->connect(url, user, password);

I get:

First-chance exception at 0x75c99673 in DBTest.exe: Microsoft C++ exception:      std::bad_alloc at memory location 0x0027f1ec..
First-chance exception at 0x75c99673 in DBTest.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0027eb78..
First-chance exception at 0x75c99673 in DBTest.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..
Unhandled exception at 0x75c99673 in DBTest.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0027eb78..
The program '[1236] DBTest.exe: Native' has exited with code -529697949 (0xe06d7363).

…at driver->connect(...). I've tried without assigning it to con, same thing (meaning problem is in get_driver_instance())?

c++
mysql
driver
asked on Stack Overflow Dec 9, 2011 by Mercurial • edited Dec 9, 2011 by Lightness Races in Orbit

1 Answer

-1

It's a little late but for solve this problem, I tried this and it worked for me

sql::mysql::Driver *driver = get_driver_instance();

const sql::SQLString host = "tcp://127.0.0.1:3306";
const sql::SQLString user = "root";
const sql::SQLString pass = "*****";

sql::mysql::Connection *con = driver->connect(host, user, pass);
answered on Stack Overflow Oct 29, 2017 by Marcelo Rafael

User contributions licensed under CC BY-SA 3.0