【发布时间】:2015-11-18 03:51:29
【问题描述】:
我只是使用来自 mysql 站点的示例代码。如果我在调试中执行此程序,它将编译并运行。如果我在发行版中编译,它会给我标题中的错误。我从 oracle 站点下载了所有连接器和服务器,所以一切都是最新的。我什至编译了最新版本的 c++ 连接器和 c 连接器。我对此进行了很多搜索并尝试了他们所说的操作,但无法解决此问题。我所看到的 lib 和 dll 文件列出了 mysql_get_option 函数。我确保我的计算机上没有杂散的 dll 或 lib 文件。我检查了系统路径变量以确保它没有指向某个随机区域。我正在使用 Vs2013。
请帮助我已经尝试解决这个问题一个星期,我的大脑快要爆炸了!!谢谢你的建议。
附: 我将编程作为一种爱好,所以很可能我忽略了一些微不足道的事情。
/* Copyright 2008, 2010, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
There are special exceptions to the terms and conditions of the GPL
as it is applied to this software. View the full text of the
exception in file EXCEPTIONS-CONNECTOR-C++ in the directory of this
software distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* 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 World0000........ 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("*****", "*****", "*****");
/* Connect to the MySQL test database */
//con->setReadOnly(true);
con->setSchema(*****);
cout << "\nHere!";
stmt = con->createStatement();
res = stmt->executeQuery("SELECT DISTINCT eqdkp10_raid_attendees.raid_id, eqdkp10_raids.raid_value \
FROM eqdkp10_raids LEFT JOIN eqdkp10_raid_attendees ON eqdkp10_raids.raid_id \
= eqdkp10_raid_attendees.raid_id AND eqdkp10_raid_attendees.member_id=2");
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;
system("PAUSE");
return EXIT_SUCCESS;
}
【问题讨论】: