Advertisement
m4ly

mysql++

Oct 2nd, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <cppconn/datatype.h>
  2. #include <cppconn/config.h>
  3. #include <cppconn/resultset.h>
  4. #include <cppconn/statement.h>
  5.  
  6. #include <mysql_connection.h>
  7. #include <mysql_driver.h>
  8. #include <mysql_error.h>
  9.  
  10. using namespace std;
  11. using namespace sql;
  12.  
  13. int main(void) {
  14.     sql::mysql::MySQL_Driver *driver;
  15.     sql::Statement *stmt;
  16.     sql::ResultSet *res;
  17.     sql::Connection *con;
  18.     string breakpoint;
  19.     driver = sql::mysql::get_mysql_driver_instance();
  20.     con = driver->connect("tcp://127.0.0.1:4406", "", "");
  21.     stmt = con->createStatement();
  22.     res = stmt->executeQuery("SELECT Name, Population FROM world.city limit 10");
  23.     while (res->next()) {
  24.         cout << "Name = '" << res->getString("Name") << "'" << " Pop = " << res->getInt("Population")<< endl;
  25.     }
  26.     cin >> breakpoint;
  27.     delete res;
  28.     delete stmt;
  29.     delete con;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement