您好,欢迎访问一九零五行业门户网

c++-C++连接mysql数据库时,用getString()方法总是出错

mysqlc++数据库
http://www.cnblogs.com/joeblackzqq/p/4332945.html
我按照上面这个链接的教程,用了第二种connector c++的方法,配置好boost的路径和mysql的路径后,就修改了一下范例的代码:
#include #include #include #include #include mysql_driver.h#include mysql_connection.h#include cppconn/driver.h#include cppconn/statement.h#include cppconn/prepared_statement.h#include cppconn/metadata.h#include cppconn/exception.husing namespace std;using namespace sql;int main(){ sql::mysql::mysql_driver *driver = 0; sql::connection *conn = 0; try { driver = sql::mysql::get_mysql_driver_instance(); conn = driver->connect(tcp://localhost:3306/tree, root, 123); cout createstatement(); stat->execute(set names 'gbk'); resultset *res; res = stat->executequery(select * from testuser); while (res->next()) { cout getint(id) getstring(name) getstring(address)
为此我创建了一个数据库tree和表testuser:
create database tree;use tree;create table testuser(id int(4) primary key,name char(25),address varchar(45));desc testuser;insert into testuser values(1,'tom','china beijing'),(2,'amy','america newyork');select*from testuser;
准备工作都做好了,然后就开始执行:
问题来了:
其它类似信息

推荐信息