mysql connector放在哪_关于MySQL Connector/C++那点事儿

如果从官方直接下载的库使用时遇到类似如下的问题:

f219fc32ef21ab4c8f8aac9c9ffe0840.png

原因是官方提供的库文件版本与需要的库版本不匹配,提供的debug版本使用的是MT版本,在debug模式下会出现内存错误,导致crash。

TestC.exe中的...dll有未经处理的异常:读取位置时发生访问冲突。

那么可能需要自己手动编译源码(参考编译MySQL Connector/C++的资料)啦:

重新设置包含目录和库目录(实际中请把想要的头文件和库文件最好放到自己的工程目录里的第三方库或头文件如Libs之类的目录下,保证工程的可一致性,而不是像这里这样F:\Tools\....这样):

4b6f91f988052e7f16cb4bd70cd3b8c6.png 

1ed77b10ac01d6f82e454bf8a82ae2aa.png

重新编译运行:

4861520bf9ee6cd2ad7e5017e0078001.png

#include

#include

#include

#include

#include

#include

#include

using namespace std;

int main(void)

{

cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl;

try

{

sql::Driver *driver;

sql::Connection *con;

sql::Statement *stmt;

sql::ResultSet *res;

/* 连接mysql服务器 */

driver = get_driver_instance();

con = driver->connect("tcp://127.0.0.1:3307", "root", "*****");

con->setSchema("test");

stmt = con->createStatement();

res = stmt->executeQuery("SELECT 'Hello World!' AS _message");

while (res->next()) {

//通过列别名访问

cout << res->getString("_message") << endl;

//通过列偏移

cout << res->getString(1) << endl;

}

delete res;

delete stmt;

delete con;

}

catch (sql::SQLException &e)

{

cout << "# ERR: SQLException in " << __FILE__;

cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;

cout << "# ERR: " << e.what();

cout << " (MySQL error code: " << e.getErrorCode();

cout << ", SQLState: " << e.getSQLState() << " )" << endl;

}

cin.get();

return EXIT_SUCCESS;

}

MySQL Connector/C++文档:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值