Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <iostream>
- #include <sstream>
- #include <stdexcept>
- #include "mysql_connection.h"
- #include <cppconn/driver.h>
- #include <cppconn/exception.h>
- #include <cppconn/resultset.h>
- #include <cppconn/statement.h>
- #include <cppconn/prepared_statement.h>
- #define EXAMPLE_HOST "localhost"
- #define EXAMPLE_USER "root"
- #define EXAMPLE_USER "Quadro88"
- #define EXAMPLE_DB "db_ved_wine"
- using namespace std;
- int main()
- {
- try {
- /* INSERT TUTORIAL CODE HERE! */
- sql::mysql::MySQL_Driver *driver;
- sql::Connection *con;
- sql::Statement *stmt;
- driver = sql::mysql::get_mysql_driver_instance();
- con = driver->connect("tcp://"EXAMPLE_HOST":3306", EXAMPLE_USER, EXAMPLE_USER);
- stmt = con->createStatement();
- stmt->execute("USE " EXAMPLE_DB);
- stmt->execute("SELECT * FROM products");
- delete stmt;
- delete con;
- } catch (sql::SQLException &e) {
- /*
- The MySQL Connector/C++ throws three different exceptions:
- - sql::MethodNotImplementedException (derived from sql::SQLException)
- - sql::InvalidArgumentException (derived from sql::SQLException)
- - sql::SQLException (derived from std::runtime_error)
- */
- cout << "# ERR: SQLException in " << __FILE__;
- cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
- /* Use what() (derived from std::runtime_error) to fetch the error message */
- cout << "# ERR: " << e.what();
- cout << " (MySQL error code: " << e.getErrorCode();
- cout << ", SQLState: " << e.getSQLState() << " )" << endl;
- return EXIT_FAILURE;
- }
- cout << "Done." << endl;
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement