栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用C ++连接MySQL数据库

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用C ++连接MySQL数据库

在这里找到:

#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>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;    driver = get_driver_instance();  con = driver->connect("tcp://127.0.0.1:3306", "root", "root");    con->setSchema("test");  stmt = con->createStatement();  res = stmt->executeQuery("SELECT 'Hello World!' AS _message"); // replace with your statement  while (res->next()) {    cout << "t... MySQL replies: ";        cout << res->getString("_message") << endl;    cout << "t... MySQL says it again: ";        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 pre: " << e.getErrorCode();  cout << ", SQLState: " << e.getSQLState() << " )" << endl;}cout << endl;return EXIT_SUCCESS;}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/421139.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号