Can't connect to MySql database
Posted by: Guy Shen
Date: July 13, 2010 06:50PM

Hey guys.
I've tried for the past few hours connecting to my MySQL database using C++, but it keeps failing and I dont know why, and I'm really starting to get frustrated with this stuff.
Hope you can help.

Well, as I said, I'm trying to fetch some data from a table inside my MySQL database, using C++ code. So, firstly, I just tried setting it up and create a connection, so this is what I did :
1.Installed the connector
2. Created a new project
3. Configured it as Active(Release)
4. In properties, under C/C++ -> General -> Additional Include Directories, I've added the connector's "include" folder
5. In Linker -> General -> Additional Libary Directories, I've added the "lib/opt" subfolder.
6. I've also added "mysqlcppconn.lib" under Linker -> Input -> Additional Dependencies

After all of this, I tried running this simple code:
---------------------------------------------------
#include <stdlib.h>
#include <iostream>

#include "mysql_connection.h"
#include "mysql_driver.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

using namespace std;

int main(void)
{ sql:river *driver;
sql::Connection *con;
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
}
----------------------------------------------------

But I just keeping getting this error:
1>NEW_C++_mySQL.obj : error LNK2019: unresolved external symbol __imp__get_driver_instance referenced in function _main

So, I've tried changing the "driver=get_driver_instance();" into
------------------------------------------------
driver = sql::mysql::MySQL_Driver::Instance();
------------------------------------------------
But then I get this error :

1>NEW_C++_mySQL.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class sql::mysql::MySQL_Driver * __cdecl sql::mysql::MySQL_Driver::Instance(void)" (__imp_?Instance@MySQL_Driver@mysql@sql@@SAPAV123@XZ) referenced in function _main

I just can't figure out what's wrong with the instancing function, since I believe I linked everything fine.

Any help would be very appreciated, since I need to finish this small project in a very small period of time.

Thanks again

Options: ReplyQuote


Subject
Views
Written By
Posted
Can't connect to MySql database
1816
July 13, 2010 06:50PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.