MySQL Connector/C++ 使用中出现的一个错误
2014-12-15 14:33
746 查看
在使用过程中,一定不要释放sql:driver,因为这是一个全局的,你释放以后,下一次重新连接的时候,必然要出段错误。
红色的这一行,在实际项目中是有问题的,不能用智能指针来释放。在你的程序中,你根本就不需要释放这个mysql::MySQL_Driver。我一直都没有找到MySQL Connector/C++的使用文档,不知道是没有,还是什么情况。
#include <stdlib.h> #include <iostream> #include "mysql_connection.h" #include <boost/shared_ptr> #include <cppconn/driver.h> #include <cppconn/exception.h> using namespace std; int main(void) { cout << endl; cout << "Let's have MySQL count from 10 to 1..." << endl; try { sql::Driver *driver; sql::Connection *con; sql::ConnectOptionsMap connection_properties; connection_properties["hostName"] = std::string ( host_ ); connection_properties["userName"] = std::string ( user_ ); connection_properties["password"] = std::string ( pawd_ ); connection_properties["schema"] = std::string ( db_ ); <span style="color:#FF6666;">boost::shared_ptr<mysql::MySQL_Driver> driver_(sql::mysql::get_mysql_driver_instance());</span> boost::shared_ptr<sql::Connection> conn_(driver_->connect ( connection_properties )); } catch ( SQLException &e ) { LOG_ERROR<<"数据库 连接异常: "<<e.what(); } catch ( std::runtime_error &e ) { LOG_ERROR<<"数据库 运行时异常: "<<e.what(); } }
红色的这一行,在实际项目中是有问题的,不能用智能指针来释放。在你的程序中,你根本就不需要释放这个mysql::MySQL_Driver。我一直都没有找到MySQL Connector/C++的使用文档,不知道是没有,还是什么情况。
相关文章推荐
- C++使用MySQL-Connector/C++连接MySQL出现LNK2019错误
- C++使用MySQL-Connector/C++连接MySQL出现LNK2019错误的解决方法
- Connector/c++ 查询Mysql,出现 can't fetch because not on result set 错误
- ubuntu上在使用c/c++连接mysql时,出现undefined reference错误解决办法
- 使用VS 2008(带sp1)编译VC 6.0的一个工程,出现下面的编译错误
- mysql-connector-c++-noinstall-1.0.5-win32-vs2005 使用心得
- c++使用list出现错误
- 在使用STRUTS标签修改MYSQL里面的数据时出现错误
- S2SH集成,数据库使用mysql,查询的时候出现字符集的错误
- 使用MySQLConnector/C++连接MySQL数据库
- 在CentOS里使用MySQL Connector/C++
- 使用MySQL connector/C++链接MySQL数据库
- 问题: 在eclipse里使用ctr+shift+t打开一个类的时候,出现错误:Class file name must end with .class
- "执行SQL语句时出现问题操作必须使用一个可更新的查询"错误的解决方法
- C++使用c写的函数,出现连接错误.
- [原]用c#做了一个桌面程序用来分离excel文件里的数据时出现“操作必须使用一个可更新的查询”错误的解决
- 使用memset出现的一个错误
- C++ 调用mysql的存储过程 出现1312错误
- mysql connector c++与 visual studio 2012 联合使用
- 执行SQL语句时出现问题操作必须使用一个可更新的查询错误的解决方法