MySQL Connector / C ++示例代码不起作用

时间:2012-04-13 10:26:49

标签: c++ mysql

您好我刚开始在appication中使用C ++ MySql Connector 发布| Win3

我的错误:

  

警告1警告C4627:'#include':查看时跳过   对于预编译的头文件,请使用c:\​​ Documents and Settings ...

     

警告2警告C4627:'#include':看时跳过   对于预编译的头文件,请使用c:\​​ Documents and Settings ...

     

错误3致命错误C1083:无法打开包含文件:   'boost / variant.hpp':没有这样的文件或目录C:\ Program   Files \ MySQL \ MySQL Connector C ++   1.1.0 \ include \ cppconn \ connection.h 29 lacznik

#include <cstdlib>
#include <iostream>
#include "stdafx.h"
#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;
}

1 个答案:

答案 0 :(得分:0)

  

警告1警告C4627:'#include':在查找预编译头时跳过使用c:\​​ Documents and Settings ...

表示“预编译头”包含

#include "stdafx.h"

应该是第一个包含的标题。