我正在使用 c++ 连接器连接到 MYSQL,我正在使用循环一次又一次地获取数据。我不确定是否要关闭或删除下面代码中的 pstmt、con 和 res 变量?什么时候使用close,什么时候使用delete?
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()