Advertisement
s_m4rt

Untitled

Nov 21st, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <stdio.h> // for printf
  2. #include <SQLAPI.h> // main SQLAPI++ header
  3. #include <iostream>
  4. #include <stdlib.h>
  5. #include <string>
  6. int main(int argc, char* argv[])
  7. {
  8. SAConnection con; // create connection object
  9. try
  10. {
  11. // connect to database
  12. // in this example it is Oracle,
  13. // but can also be Sybase, Informix, DB2
  14. // SQLServer, InterBase, SQLBase and ODBC
  15. con.Connect(
  16. "Przychodnia", // database name
  17. "marta", // user name
  18. "marta", // password
  19. SA_Oracle_Client); //client name
  20. printf("We are connected!\n");
  21. // Disconnect is optional
  22. // autodisconnect will ocur in destructor if needed
  23. con.Disconnect();
  24. printf("We are disconnected!\n");
  25. }
  26. catch(SAException &x)
  27. {
  28. // SAConnection::Rollback()
  29. // can also throw an exception
  30. // (if a network error for example),
  31. // we will be ready
  32. try
  33. {
  34. // on error rollback changes
  35. con.Rollback();
  36. }
  37. catch(SAException &)
  38. {
  39. }
  40. // print error message
  41. printf("%s\n", (const char*)x.ErrText());
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement