Skip to content

Instantly share code, notes, and snippets.

@larryzhao
Created September 8, 2015 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larryzhao/9dc2db15621d76939f37 to your computer and use it in GitHub Desktop.
Save larryzhao/9dc2db15621d76939f37 to your computer and use it in GitHub Desktop.
// MySQLTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include "mysql_connection.h"
#include "mysql_driver.h"
#include "cppconn\statement.h"
#include "cppconn\resultset.h"
using namespace sql;
using namespace std;
int main()
{
mysql::MySQL_Driver *driver;
Connection *conn;
Statement *stmt;
ResultSet *result;
driver = sql::mysql::get_mysql_driver_instance();
conn = driver->connect("tcp://127.0.0.1:3306", "root", "admin");
conn->setSchema("sakila");
stmt = conn->createStatement();
result = stmt->executeQuery("SELECT 'Hello World!' AS _message");
result->next();
string message = result->getString("_message");
delete result;
delete stmt;
delete conn;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment