linuxc操作数据库
来源:互联网 发布:迭代器java 线程安全 编辑:程序博客网 时间:2024/05/29 17:45
#include <mysql++.h>
#include <iostream>
using namespace std;
int main()
{
const char* db = 0, *server = 0, *user = 0, *password = "";
db = "test";
server = "localhost";
user = "zhxilin";
password = "";
mysqlpp::Connection conn(false);
if (conn.connect(db, server, user, password)) {
cout << "connect db succeed. " << endl;
mysqlpp::Query query = conn.query("SELECT * FROM Student");
if (mysqlpp::StoreQueryResult res = query.store()) {
cout.setf(ios::left);
cout << setw(31) << "Sid" <<
setw(10) << "Sname" <<
setw(10) << "Sage" <<
setw(10) << "Sgender" <<
setw(10) << "SDepartment" << endl;
mysqlpp::StoreQueryResult::const_iterator it;
for (it = res.begin(); it != res.end(); ++it) {
mysqlpp::Row row = *it;
cout << setw(30) << row[0] << ' ' <<
setw(9) << row[1] << ' ' <<
setw(9) << row[2] << ' ' <<
setw(9) << row[3] << ' ' <<
setw(9) << row[4] << ' ' <<
endl;
}
}
} else {
cout << "connect db fail. " << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
const char* db = 0, *server = 0, *user = 0, *password = "";
db = "test";
server = "localhost";
user = "zhxilin";
password = "";
mysqlpp::Connection conn(false);
if (conn.connect(db, server, user, password)) {
cout << "connect db succeed. " << endl;
mysqlpp::Query query = conn.query("SELECT * FROM Student");
if (mysqlpp::StoreQueryResult res = query.store()) {
cout.setf(ios::left);
cout << setw(31) << "Sid" <<
setw(10) << "Sname" <<
setw(10) << "Sage" <<
setw(10) << "Sgender" <<
setw(10) << "SDepartment" << endl;
mysqlpp::StoreQueryResult::const_iterator it;
for (it = res.begin(); it != res.end(); ++it) {
mysqlpp::Row row = *it;
cout << setw(30) << row[0] << ' ' <<
setw(9) << row[1] << ' ' <<
setw(9) << row[2] << ' ' <<
setw(9) << row[3] << ' ' <<
setw(9) << row[4] << ' ' <<
endl;
}
}
} else {
cout << "connect db fail. " << endl;
}
return 0;
}
0 0
- linuxc操作数据库
- Linuxc 文件操作讲座知识
- Linuxc
- linuxc
- LinuxC函数库参考(进程操作)
- LinuxC学习之字符和字符串操作
- LinuxC双向链表的各种操作
- LinuxC编程实战之文件操作
- linuxc不带缓存的文件操作
- 总结一下linuxc常用操作命令
- linuxC编程之文件操作与进程初步
- LinuxC/C++编程(1)—文件操作
- LinuxC/C++编程(2)—文件夹操作
- LinuxC编程实战学习——第六章文件操作
- linuxC系统编程——文件的I/O操作
- Android与LinuxC目录创建以及文件读写操作
- linuxC编程
- LinuxC socekt
- LeetCode 561. Array Partition I
- Problem J: Color Circle----dfs
- linux 下vim编辑器使用方法及技巧
- 【BZOJ】1922 [Sdoi2010]大陆争霸 带限制最短路
- 官网方法提升AndroidStudio编译速度
- linuxc操作数据库
- 【数据结构基础】数的层次遍历
- 【Linux】atexit 的验证
- A*算法实现八数码问题
- Stringbuffer的一般用法
- Select2的用例
- 安卓学习笔记---Android播放Gif图片
- 移动端的三种输入方式
- 动态规划_最大非降子序列的长度