-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.cpp
More file actions
82 lines (73 loc) · 2.05 KB
/
Copy pathDatabase.cpp
File metadata and controls
82 lines (73 loc) · 2.05 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
77
78
79
80
81
82
#include <stdlib.h>
#include <iostream>
#include <driver.h>
#include <exception.h>
#include <resultset.h>
#include <statement.h>
#include <prepared_statement.h>
#include "Database.h"
using namespace sql;
using namespace std;
Database::Database(){
try {
connectLocally = false;
driver = get_driver_instance();
con = driver->connect("sql9.freemysqlhosting.net", "sql9372596", "fNf8Kr8wZD");
con->setSchema("sql9372596");
} catch(sql::SQLException &e){
cout <<"cannot connect to remote server"<<endl;
connectLocally = true;
}
if(connectLocally){
try {
driver = get_driver_instance();
con = driver->connect("tcp://localhost:3306", "root", "");
con->setSchema("quicktracker");
cout << "connected locally"<<endl;
} catch(sql::SQLException &e){
cout << "Cannot connect to local server"<<endl;
}
}
}
Database::Database(string serverName, string userName, string password){
try {
connectLocally = false;
driver = get_driver_instance();
con = driver->connect(serverName, userName, password);
con->setSchema("sql9372596");
} catch(sql::SQLException &e){
cout <<"cannot connect to remote server"<<endl;
connectLocally = true;
}
if(connectLocally){
try {
driver = get_driver_instance();
con = driver->connect("tcp://localhost:3306", "root", "");
con->setSchema("quicktracker");
cout << "connected locally"<<endl;
} catch(sql::SQLException &e){
cout << "Cannot connect to local server"<<endl;
}
}
}
Database::Database(int cond, string serverName, string userName, string password, string databaseName){
if (cond == 1){
try {
connectLocally = false;
driver = get_driver_instance();
con = driver->connect(serverName, userName, password);
con->setSchema(databaseName);
} catch(sql::SQLException &e){
cout <<"cannot connect to server"<<endl;
}
}else{
try {
connectLocally = false;
driver = get_driver_instance();
con = driver->connect(serverName, userName, password);
con->setSchema("sql9372596");
} catch(sql::SQLException &e){
cout <<"cannot connect to remote server"<<endl;
}
}
}