#include "StdAfx.h"
#include <stdlib.h>
#include <iostream>
#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;
try{
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;
driver = get_driver_instance();
con = driver->connect("REMOVED", "REMOVED", "REMOVED");
con->setSchema("REMOVED");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT username FROM player WHERE id=1");
cout << "Username: " << res->getString("username") << endl;
delete res;
delete con;
cout << "Done.";
system("pause");
}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() << endl;
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
system("pause");
}
return 0;
}
变成... http://i.imgur.com/cIVnl.png
发生了什么?:( 这只是我使用 C++ 的第二天,所以请原谅我的严重格式化编码和其他 nooby 错误。这总是在我遇到未处理的异常之前出现。