-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase_backup.cpp
More file actions
70 lines (59 loc) · 1.69 KB
/
Copy pathDatabase_backup.cpp
File metadata and controls
70 lines (59 loc) · 1.69 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
#include <stdlib.h>
#include <iostream>
#include <driver.h>
#include <exception.h>
#include <resultset.h>
#include <statement.h>
#include <prepared_statement.h>
using namespace sql;
using namespace std;
class Database : Database{
private:
Driver *driver;
Connection *con;
Statement *stmt;
ResultSet *res;
PreparedStatement *pstmt;
public:
Database(string serverName, string userName, string password){
try {
driver = get_driver_instance();
con = driver->connect(serverName, userName, password);
con->setSchema("sql9372596");
}catch(sql::SQLException &e){
cout << "# ERR: " << e.what()<<endl;
cout << "MySQL error code: " << e.getErrorCode()<<endl;
cout << ", SQLState: " << e.getSQLState()<<endl;
}
}
~Database(){
delete stmt;
delete con;
}
void selectCustomers(){
this->stmt= con->createStatement();
this->res = stmt->executeQuery("SELECT * FROM tbl_customers");
while(this->res->next()){
cout << "id = " <<res->getInt("customer_id") <<res->getString("customer_id") <<endl;
}
}
void selectBusiness(){
this->stmt= con->createStatement();
this->res = stmt->executeQuery("SELECT * FROM tbl_businesses");
while(this->res->next()){
cout << "id = " << res->getInt("business_id") << res->getString("business_name") <<endl;
}
}
void insertCustomer(){
//this->stmt= con->createStatement();
this->pstmt = con->prepareStatement("INSERT INTO tbl_customers(customer_username, customer_firstName) VALUES ('Test', 'Testings')");
this->pstmt->executeUpdate();
}
};
/*int main(){
Database* test = new Database("sql9.freemysqlhosting.net", "sql9372596", "fNf8Kr8wZD");
test->selectBusiness();
test->insertCustomer();
return 0;
}
*/