C++ 从c+连接+;在Ubuntu机器上安装mysql
我在Ubuntu操作系统的虚拟机上运行MySQL 我想用Windows 7 OS C++来读取和写入MySQL数据,我很少有问题:C++ 从c+连接+;在Ubuntu机器上安装mysql,c++,mysql,virtual-machine,C++,Mysql,Virtual Machine,我在Ubuntu操作系统的虚拟机上运行MySQL 我想用Windows 7 OS C++来读取和写入MySQL数据,我很少有问题: 我如何知道MySQL服务器的IP地址?它是Ubuntu虚拟机的IP还是127.0.0.1 如何使用C++读取数据?我需要司机还是别的什么 我试着去做;安装VisualStudio Express 2010 C++,在Ubuntu上安装MySQL .< 我还尝试了以下代码:来自oracle站点 /* Include directly the different
/*
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 World!' »";
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;
}
/*
直接包括不同的
来自cppconn/和mysql_driver.h+mysql_util.h的头文件
(和mysql_connection.h)。这将减少你的构建时间!
*/
#包括“mysql\u connection.h”
#包括
#包括
#包括
#包括
使用名称空间std;
内部主(空)
{
cout-setSchema(“测试”);
stmt=con->createStatement();
res=stmt->executeQuery(“选择“Hello World!”作为消息”);
while(res->next()){
对于电脑新手来说,这可能是一项相当艰巨的任务。我知道,我仍然想尝试一些教程