Skip to content

Instantly share code, notes, and snippets.

@larryzhao larryzhao/test.cpp
Created Sep 8, 2015

Embed
What would you like to do?
// 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
You can’t perform that action at this time.