mysql c++开发实例_mysql c++ jdbc 示例

#include "JdbcHelper.h"#includeJdbcHelper::JdbcHelper(const std::string& host, const std::string& username, const std::string& passwd, const std::string&database)

{this->host =host;this->username =username;this->passwd =passwd;this->database =database;this->conn =NULL;try{this->driver =get_driver_instance();

}catch (sql::SQLException &e) {this->printSQLException(e, "get_driver_instance");

}if (driver ==NULL) {

std::cout<< "driver is null" <<:endl>

}

}

JdbcHelper::~JdbcHelper()

{

}int JdbcHelper::jdbc_connect(boolenableSSL)

{if (NULL !=conn) {return -1;

}this->m_enableSSL =enableSSL;try{

sql::ConnectOptionsMap opts;

opts["hostName"] = this->host;

opts["userName"] = this->username;

opts["password"] = this->passwd;if(enableSSL) {//默认使用SSL

}else{

opts["OPT_SSL_MODE"] =sql::SSL_MODE_DISABLED;

}

opts["OPT_RECONNECT"] = sql::ConnectPropertyVal(true);this->conn = driver->connect(opts);if (NULL ==conn) {

printf("conn id null\n");return -2;

}//选择数据库

sql::SQLString catalog(this->database);

conn->setSchema(catalog);return 0;

}catch (sql::SQLException &e) {this->printSQLException(e, "connect");

}return -3;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值