-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathV_OraDatabase.h
59 lines (51 loc) · 1.24 KB
/
V_OraDatabase.h
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
#pragma once
#include <occi.h>
#include <string>
#include <list>
#include <iostream>
using namespace oracle::occi;
using namespace std;
class V_OraDatabase
{
private:
Environment *env;
Connection *conn;
Statement *stmt;
public:
V_OraDatabase()
{
env = Environment::createEnvironment (Environment::DEFAULT);
conn = env->createConnection ("vasa", "vasa", "//ItDogAnimal:1521/ORCL");
}
~V_OraDatabase()
{
env->terminateConnection (conn);
Environment::terminateEnvironment (env);
}
std::list<std::string*>* getData()
{
std::list<std::string*>* strList = new std::list<std::string*>();
string sqlStmt = "SELECT OWNER, OBJECT_NAME FROM ALB where object_id between 1 and 20";
stmt = conn->createStatement (sqlStmt);
ResultSet *rset;
try{
rset = stmt->executeQuery ();
while (rset->next())
{
std::string* strarr = new std::string[2];
strarr[0].assign(rset->getString(1));
strarr[1].assign(rset->getString(2));
strList->push_back(strarr);
}
}catch(SQLException ex)
{
int ora = ex.getErrorCode();
std::string e(ex.getMessage());
cout<<"Exception thrown for displayVersion";
cout<<"Error number: ORA-"<< ora<<e;
}
stmt->closeResultSet (rset);
conn->terminateStatement (stmt);
return strList;
}
};