Guest User

Untitled

a guest
Aug 15th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. mysql cpp connector throwing UnknownException while connecting
  2. // Specify our connection target and credentials
  3. const string server = "tcp://127.0.0.1:3306";
  4. const string username = "root";
  5. const string password = "";// No password - thanks, WAMP Server!
  6.  
  7. // Try to get a driver to use to connect to our DBMS
  8. try {
  9. driver = get_driver_instance();
  10. if( driver == NULL )
  11. throw SQLException("Null driver instance returned.");
  12. }
  13. catch (SQLException e) {
  14. cout << "Could not get a database driver. Error message: " << e.what() << endl;
  15. return -3;
  16. }
  17.  
  18. // Try to connect to the DBMS server
  19. try {
  20. dbConn = driver->connect(server, username, password);
  21. }
  22. catch (sql::SQLException e) {
  23. cout << "Could not connect to database. Error message: " << e.getSQLStateCStr() << " Error Code: " << e.getErrorCode() << endl;
  24. cout << "Could not connect to database. Error: " << e.what() << endl;
  25. return -1;
  26. }
Add Comment
Please, Sign In to add comment