mysql database errors using visual c + +
Jan 14, 2013 at 7:04pm UTC
hello friendly people, good way to say my problem I want to do a database static, not dynamic, in mysql using visual c + +.
already achieved everything related to installing, but when I use an example official document of mysql connector-cpp gives me a series of errors.
excuse my bad English
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>
/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
int main(void )
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306" , "root" , "flony1" );
/* Connect to the MySQL test database */
con->setSchema("test" );
stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message" );
while (res->next()) {
cout << "\t... MySQL replies: " ;
/* Access column data by alias or column name */
cout << res->getString("_message" ) << endl;
cout << "\t... MySQL says it again: " ;
/* Access column fata by numeric offset, 1 is the first column */
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete con;
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}
1>------ Operación Compilar iniciada: proyecto: ConsoleApplication1, configuración: Debug Win32 ------
1> Source.cpp
1>Source.obj : error LNK2019: símbolo externo _get_driver_instance sin resolver al que se hace referencia en la función _main
1>C:\Users\flony\documents\visual studio 2012\Projects\ConsoleApplication1\Debug\ConsoleApplication1.exe : fatal error LNK1120: 1 externos sin resolver
========== Compilar: 0 correctos, 1 incorrectos, 0 actualizados, 0 omitidos ==========
Jan 15, 2013 at 1:46am UTC
You need to link against the pre-compiled library for mySQL. This error means it's unable to find the implementation of the _get_driver_instance method.
Topic archived. No new replies allowed.