我正在尝试在 VC++ 中构建一个简单的 MySQL db 应用程序,但遇到了一个小问题。
我正在使用 MySQL 连接器 C++ 1.1.0 和 Visual Studio 2012(如果重要,请使用高级版)
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
/* MySQL Connector/C++ specific headers */
#include <driver.h>
#include <connection.h>
#include <statement.h>
#include <prepared_statement.h>
#include <resultset.h>
#include <metadata.h>
#include <resultset_metadata.h>
#include <exception.h>
#include <warning.h>
#include "mysql_driver.h"
#include "mysql_connection.h"
#define DBHOST "tcp://127.0.0.1:3306"
#define USER "root"
#define PASSWORD "root"
#define DATABASE "test"
using namespace std;
using namespace sql;
int _tmain(int argc, char *argv[]){
// I'm alive
cout << "Hello World!" << endl;
// necessary variables
Driver *driver;
Connection* con;
Statement *stmt;
ResultSet *res;
/*PreparedStatement *prep_stmt;
Savepoint *savept;*/
//
driver = get_driver_instance();
// Connect to DB
con = driver->connect("tcp//127.0.0.1:3306", "root", "root");
//
con->setAutoCommit(false);
// set schema
con->setSchema("world");
// create statement object
stmt = con->createStatement();
// alert user
cout << "Executing query: \"SELECT * FROM city\"" << endl;
// execute query "SELECT * FROM city"
res = stmt->executeQuery("SELECT * FROM city");
// alert user
cout << "\tRetrieved " << res->rowsCount() << " row(s)." << endl;
// fetch data
while(res->next()){
cout << res->getString("Name") << endl;
}
system("pause");
// Clean up
delete res;
delete stmt;
/*delete prep_stmt;*/
con->close();
delete con;
return 0;
} // end main
我将其构建为调试模式下的 Win32 控制台应用程序,将配置更改为 x64 并将 mysqlcppconn.dll 移动到输出目录。代码正在正确构建(*我认为我已经正确添加了必要的包含目录以及其他库依赖项/相关路径)。但是,当我尝试运行它时,我得到以下调试输出:
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Users\RBanerjee\Documents\Visual Studio 2012\Projects\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Users\RBanerjee\Documents\Visual Studio 2012\Projects\ConsoleApplication1\x64\Debug\mysqlcppconn.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\libmysql.dll'. Module was built without symbols.
'ConsoleApplication1.exe' (Win32): Unloaded 'C:\Windows\System32\libmysql.dll'
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\System32\libmysql.dll'. Module was built without symbols.
'ConsoleApplication1.exe' (Win32): Unloaded 'C:\Windows\System32\libmysql.dll'
The program '[4172] ConsoleApplication1.exe' has exited with code -1073741701 (0xc000007b).
我对接下来要做什么有点迷茫,我真的只是希望能够开发一个可以连接到 MySQL 数据库并与之交互的 Windows 应用程序。我将不胜感激有关此问题的任何帮助或指向其他教程的指针。
谢谢罗希特