MySql连接器C ++代码块

时间:2018-12-10 20:42:10

标签: c++ codeblocks mysql-connector

我正在写这篇文章,以解决mysql连接器库的错误。 我刚刚安装了它,并将其链接到代码块(MinGW为32位)中后,我想用此代码对其进行测试(我在Internet上找到了它)。

>#include "mysql_connection.h"

#include "cppconn/driver.h"
#include "cppconn/exception.h"
#include "cppconn/resultset.h"
#include "cppconn/statement.h"
#include "cppconn/prepared_statement.h"

using namespace std;

int main(void)
{
cout << endl;
cout << "Let's have MySQL count from 10 to 1..." << endl;

try {
  sql::Driver *driver;
  sql::Connection *con;
  sql::Statement *stmt;
  sql::ResultSet *res;
  sql::PreparedStatement *pstmt;

  /* 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();
  stmt->execute("DROP TABLE IF EXISTS test");
  stmt->execute("CREATE TABLE test(id INT)");
  delete stmt;

  /* '?' is the supported placeholder syntax */
  pstmt = con->prepareStatement("INSERT INTO test(id) VALUES (?)");
  for (int i = 1; i <= 10; i++) {
    pstmt->setInt(1, i);
    pstmt->executeUpdate();
  }
  delete pstmt;

  /* Select in ascending order */
  pstmt = con->prepareStatement("SELECT id FROM test ORDER BY id ASC");
  res = pstmt->executeQuery();

  /* Fetch in reverse = descending order! */
  res->afterLast();
  while (res->previous())
    cout << "\t... MySQL counts: " << res->getInt("id") << endl;
  delete res;

  delete pstmt;
  delete con;

除了启动后,我收到此错误: “ include \ jdbc \ cppconn \ build_config.h | 59 |错误:预期的构造函数,析构函数或类型转换(在'('toke”之前

在build_config错误的行,有这句话: “ __pragma(warning(disable:4251))” 我看着它,但找不到解决方案。如果有人想帮助我,我将不胜感激。

0 个答案:

没有答案