| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 
 |  
#include <iostream>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
 
using namespace std;
 
int main(void)
{
cout << endl;
cout << "Premier test du connecteur C++ Mysql" << endl;
 
 
try {
 
  sql::Driver* driver;
  sql::Connection* con;
  sql::Statement* stmt;
  sql::ResultSet* res;
 
 
  driver = get_driver_instance();
 
  con = driver->connect("tcp://127.0.0.1:3306", "root", "");
 
 
  con->setSchema("exemple");
 
 
  stmt = con->createStatement();
 
 
  res = stmt->executeQuery("SELECT * FROM teste");
 
 
  while (res->next()) {
    cout << "\t... MySQL a repondu: ";
 
    cout << res->getString("id") << endl;
    cout << "\t... MySQL la suite : ";
 
    cout << res->getString(5) << endl;
  }
 
 
  delete res;
  delete stmt;
  delete con;
 
} catch (sql::SQLException &e) {
 
  cout << "# ERR: " << e.what();
  cout << " (code erreur MySQL: " << e.getErrorCode();
  cout << ", EtatSQL: " << e.getSQLState() << " )" << endl;
}
 
cout << endl;
 
return EXIT_SUCCESS;
} | 
Partager