当使用C++连接器连接到MySQL时,关闭或删除CON、PSTMT或RES变量?
我用C++连接到mysql,我使用循环来反复获取数据。 我不确定是否要关闭或删除下面代码中的pstmt、con和res变量? 何时使用“关闭”和何时使用“删除”当使用C++连接器连接到MySQL时,关闭或删除CON、PSTMT或RES变量?,c++,mysql,C++,Mysql,我用C++连接到mysql,我使用循环来反复获取数据。 我不确定是否要关闭或删除下面代码中的pstmt、con和res变量? 何时使用“关闭”和何时使用“删除” sql::Connection *con; sql::PreparedStatement *pstmt; con = driver->connect("tcp://127.0.0.1:3306", "root", "password"); while(3==3) { pstmt = con->p
sql::Connection *con;
sql::PreparedStatement *pstmt;
con = driver->connect("tcp://127.0.0.1:3306", "root", "password");
while(3==3)
{
pstmt = con->prepareStatement("select * from IBF (seconds<=(?)) ");
pstmt->setString(1,"1367822164");
int update_count=pstmt->executeUpdate();
res = pstmt->executeQuery();
res->afterLast();
while (res->previous())
{
cout << res->getDouble("try1") << endl;
}
pstmt->close();// changed to fix too many connections open
res->close()
}
delete pstmt;
delete res;
con->close()
如果程序将在循环结束后不久结束,则不必麻烦,当程序退出时,它们将被自动清除。如果它将继续运行一段时间,你应该清理它们。嗨,Barmar,我需要同时使用->关闭和->删除还是使用->关闭就足够了?你需要所有这些。前两个是保存从API返回的数据的数据结构,最后一个与服务器断开连接;删除pstmt;pstmt=con->prepareStatementselect*from IBF second对不起,我之前以为你只是问最后3条语句,而不是循环中的内容。其他的我不太确定。