私は 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()