Skip navigation links

User Comments

Posted by David Phillips on April 8 2011 6:57pm[Delete] [Edit]

Suggest wrapping those allocated objects in auto pointers.

std::auto_ptr< sql::Connection > apConn( driver->connect("tcp://", "root", "root" ) ) ;

std::auto_ptr< sql::Statement > apStmnt( apConn->createStatement( ) ) ;

std::auto_ptr< sql::ResultSet > apRes( apStmnt->executeQuery("SELECT 'Hello World!' AS _message") ) ;

//Dont have to manually delete the pointers now and no
//memory leak if exception is thrown