CMS 3D CMS Logo

EcalDBConnection.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <sstream>
4 #include <cstdlib>
5 #include <cstdlib>
6 #include <stdexcept>
8 
9 using namespace std;
10 using namespace oracle::occi;
11 
14 
16  string sid,
17  string user,
18  string pass,
19  int port )
20  noexcept(false)
21 {
22  stringstream ss;
23  try {
24  ss << "//" << host << ":" << port << "/" << sid;
25 
26  env = Environment::createEnvironment(Environment::OBJECT);
27  conn = env->createConnection(user, pass, ss.str());
28  stmt = conn->createStatement();
29  } catch (SQLException &e) {
30  cout<< ss.str() << endl;
31  throw(std::runtime_error("ERROR: Connection Failed: " + e.getMessage() ));
32  }
33 
34  this->host = host;
35  this->sid = sid;
36  this->user = user;
37  this->pass = pass;
38  this->port = port;
39 }
40 
42  string user,
43  string pass )
44  noexcept(false)
45 {
46  try {
47  env = Environment::createEnvironment(Environment::OBJECT);
48  conn = env->createConnection(user, pass, sid);
49  stmt = conn->createStatement();
50  } catch (SQLException &e) {
51  throw(std::runtime_error("ERROR: Connection Failed: " + e.getMessage() ));
52  }
53 
54  this->host = "";
55  this->sid = sid;
56  this->user = user;
57  this->pass = pass;
58 }
59 
61  //Close database conection and terminate environment
62  try {
63  conn->terminateStatement(stmt);
64  env->terminateConnection(conn);
65  Environment::terminateEnvironment(env);
66  } catch (SQLException &e) {
67  throw(std::runtime_error("ERROR: Destructor Failed: " + e.getMessage() ));
68  }
69 }
host
Definition: query.py:115
port
Definition: query.py:116
#define noexcept
EcalDBConnection(std::string host, std::string sid, std::string user, std::string pass, int port=1521) noexcept(false)
virtual ~EcalDBConnection() noexcept(false)