-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (65 loc) · 2.03 KB
/
Copy pathmain.cpp
File metadata and controls
76 lines (65 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <mysql_driver.h>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/exception.h>
#include <iostream>
#include <string>
int main()
{
try
{
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
driver = sql::mysql::get_mysql_driver_instance();
// Use 127.0.0.1 for the most stable connection to your local machine
// Change this:
// Use the name 'wpi509-db' and the internal port '3306'
con = driver->connect("tcp://wpi509-db:3306", "root", "p");
con->setSchema("FlightData");
sql::Statement *stmt = con->createStatement();
sql::ResultSet *res;
sql::ResultSetMetaData *res_meta;
// --- SECTION 1: DELTAS ---
std::cout << "--- Deltas Flight Data ---" << std::endl;
res = stmt->executeQuery("SELECT * FROM deltas LIMIT 1");
res_meta = res->getMetaData();
int delta_cols = res_meta->getColumnCount();
while (res->next())
{
for (int i = 1; i <= delta_cols; i++)
{
std::cout << res->getString(i);
if (i < delta_cols)
std::cout << ", ";
}
std::cout << std::endl;
}
// --- SECTION 2: SOUTHWESTS ---
std::cout << "\n--- Southwest Flight Data ---" << std::endl;
res = stmt->executeQuery("SELECT * FROM southwests LIMIT 1");
res_meta = res->getMetaData();
int sw_cols = res_meta->getColumnCount();
while (res->next())
{
for (int i = 1; i <= sw_cols; i++)
{
std::cout << res->getString(i);
if (i < sw_cols)
std::cout << ", ";
}
std::cout << std::endl;
}
// Clean up
delete res;
delete stmt;
delete con;
}
catch (sql::SQLException &e)
{
std::cerr << "SQL Error: " << e.what() << std::endl;
return 1;
}
return 0;
}