56,675
社区成员
发帖
与我相关
我的任务
分享
// mysqltest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <fstream>
/// 注:最好不要直接操作mysql,而通过接口来操作
/// mysql这么做的意义何在?难道还有多种实现?
//#include <mysql_connection.h>
//#include <mysql_driver.h>
#include <cppconn/connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
using namespace sql;
int main(int argc, char *argv[])
{
Driver *driver;
Connection *con;
//prep_stmt;
ResultSet *res;
// string query="insert into map0(1,?,?)";
///// 创建数据库连接驱动
driver = get_driver_instance();
/// 连接远程数据库
con = driver->connect("tcp://localhost:3306", "root", "m172"); // OK
/// 设置连接的数据库
con->setSchema("mapic");
/// 创建执行器
PreparedStatement *prep_stmt= con->prepareStatement("insert into map0(1,?,?)");
prep_stmt->SetString(1,"0.png");
/// 输出记录集到控制台
ifstream ifs("0.png");
ifs.seekg(0,ios::end); //设置文件指针到文件流的尾部
streampos ps = ifs.tellg();
//释放掉句柄
delete res;
delete prep_stmt;
delete con;
return 0;
}