你好,我刚刚开始使用C++ MySQL连接的器件的应用 发布| WIN3MySQL连接/ C++的示例代码是不工作
我的错误:
警告1个警告C4627: '#包括' :预编译头用C看 时跳过:跳过预编译头使用C++寻找 时:\ Documents和Settings ...
警告2警告C4627: '#包括' \的Documents and Settings ...
错误3致命错误C1083:无法打开包含文件: '升压/ variant.hpp':没有这样的文件或目录C:\ PROGRAM 文件\ MySQL的\ MySQL连接C++ 1.1.0 \包括\ cppconn \ connection.h 29 lacznik
#include <cstdlib>
#include <iostream>
#include "stdafx.h"
#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 World!' »
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("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");
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 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;
return EXIT_SUCCESS;
}
你可以正确缩进你的代码吗?我不想浪费我的志愿时间精神上跟踪示波器。 – 2012-04-13 10:31:03
此代码来自http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-examples-complete-example-1.html我不确定是否依赖y库。这是我的树http://www.wgraj.org/uploads/photos/simple/screen_6adc371c220e99f428fd221552609358.JPG – 2012-04-13 10:37:19
你为什么要给我看你的项目树?我在谈论正确缩进代码。由于SO不是付费支持网站,因此让您的问题可读性最低。 – 2012-04-13 10:42:34