C ++ MySQL程序在Windows上崩溃,错误255

时间:2017-11-07 06:32:11

标签: c++ mysql netbeans raspberry-pi mariadb

我有这个简单的C ++程序:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.cpp
 * Author: marek
 *
 * Created on 1. listopadu 2017, 22:33
 */

#include <iostream>
#include <cstdlib>
#include <stdlib.h>

/*
  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 <mysql_driver.h>

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



using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {

cout << endl;
cout << "running select as a messege" << 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://10.0.0.6:3306", "root", "*****");

  /* Connect to the MySQL test database */
  con->setSchema("mysql");

  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 data 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;




std::cout << "hello world pc 5 mysql\n"; 

#ifdef __linux__ 
    std::cout << "__linux__\n";  
#elif defined(__unix__)
    std::cout << "__unix__\n";  
#elif defined(_WIN64)
    std::cout << "_WIN64\n";  
#elif defined(_WIN32)
    std::cout << "_WIN32\n";  
#endif


#if __WORDSIZE == 64 
    std::cout << "64 bit\n";
#else 
    std::cout << "32 bit\n";  
#endif

    return 0;
}

重要的是要注意:

  • MySQL服务器(MariaDB)在本地子网上的Raspi Pi 3上运行。
  • 我可以从HeidiSQL
  • 连接到DB
  • 相同的脚本是在Raspi pi 3
  • 上成功构建

我的IDE是NetBeans,具有以下设置:

  • 工具&gt;选项&gt; C / C ++编译器是MiniGW QT,一切都存储在默认安装文件夹中。对我来说C:\ Qt \ Qt5.9.2 \,make命令是C:\ msys \ 1.0 \ bin \ make.exe。
  • 对于这个compiller,我还包括目录Mysql connector C ++ 1.1.9。也在默认安装目录中。对我来说,它将是c:\ Program Files \ MySQL \ MySQL Connector C ++ 1.1.9

我的Windows路径设置为:

C:\ProgramData\Oracle\Java\javapath;
%SystemRoot%\system32;
%SystemRoot%;
%SystemRoot%\System32\Wbem;
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
C:\Program Files\PuTTY\;
c:\msys\1.0\bin\;
C:\MinGW\bin;
c:\Qt\Qt5.9.2\5.9.2\mingw53_32\bin\;
c:\Qt\Qt5.9.2\5.9.2\;
c:\Qt\Qt5.9.2\5.9.2\mingw53_32\bin\designer.exe;
c:\Qt\Qt5.9.2\Tools\QtCreator\bin\;
c:\Qt\Qt5.9.2\Tools\QtCreator\bin\qtcreator.exe;
C:\Program Files\MariaDB\MariaDB Connector C\lib\;
C:\Program Files\MariaDB\MariaDB Connector C\lib\plugin\;
C:\Program Files\MySQL\MySQL Utilities 1.6\;
c:\Program Files\MySQL\MySQL Connector C++ 1.1.9\include\;

经过长时间的努力,我已经能够在NetBeans Windows上构建。在我存储可执行文件的同一文件夹中,我复制了一个最初缺少的mysqlcppconn.dll。

如果我从 Netbeans 运行我的程序版本,我会:

running select as a messege
RUN FAILED (exit value 255, total time: 2s)

Windows CMD我得到:

nothing. 
just windows dialog of program crashes

0 个答案:

没有答案