模糊调用重载函数

时间:2014-12-05 12:42:04

标签: c++ mysql visual-studio-2010 mysql-connector

我是mysql和c ++的新手。我想在mysql上使用C ++创建一个表。 我的代码是

  // test.cpp : Defines the entry point for the console application.
//

 #include "stdafx.h"
 #include "mysql_driver.h" 
 #include "mysql_connection.h"
 using namespace sql::mysql; 
 #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", "root");
 /* 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;

}

我正在使用Visual c ++ 2010 Express 我添加了IN ADDITIONAL INCLUDE DIRECTORIES

  C:\Programe Files\MySql\Mysqlserver5.6\include
  C:\Programe Files\MySql\Mysqlconnector6.1\include
  C:\Programe Files\MySql\Connector.c++1.1\include
  C:\User\Downloads\boost_1_53_0\boost_1_53_0

在Preproceesor定义

  WIN32
  NDEBUG
  _CONSOLE
  CPPCONNEC_PUBLIC_FUNC=

在其他图书馆目录中

  C:\Programe Files\MySql\Connector.c++1.1\lib\debug
  C:\User\Downloads\boost_1_53_0\boost_1_53_0
  C:\Programe Files\MySql\Connector.c++1.1\lib\opt
  C:\Programe Files\MySql\Mysqlserver5.6\lib

In Additional dependancy

  mysqlcppconn-static.lib
  libmysql.lib

输出:

   test.cpp(24): error C2668: 'get_driver_instance' : ambiguous call to overloaded     function
   1> C:\Program Files\MySQL\Connector.C++ 1.1\include\cppconn/driver.h(64): could be   'sql::Driver *get_driver_instance(void)'
   1> C:\Program Files\MySQL\Connector.C++ 1.1\include\mysql_driver.h(88): or       'sql::mysql::MySQL_Driver *sql::mysql::get_driver_instance(void)'
   1>while trying to match the argument list '(void)'
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

如果我正在跳过任何东西,请告诉我。 提前谢谢。

0 个答案:

没有答案