CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDBConnection.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <sstream>
4 #include <stdlib.h>
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  throw(std::runtime_error)
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  throw(std::runtime_error)
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  this->port = port;
59 }
60 
62  //Close database conection and terminate environment
63  try {
64  conn->terminateStatement(stmt);
65  env->terminateConnection(conn);
66  Environment::terminateEnvironment(env);
67  } catch (SQLException &e) {
68  throw(std::runtime_error("ERROR: Destructor Failed: " + e.getMessage() ));
69  }
70 }
int port
Definition: query.py:115
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
string host
Definition: query.py:114
virtual ~EcalDBConnection()
tuple cout
Definition: gather_cfg.py:121
EcalDBConnection(std::string host, std::string sid, std::string user, std::string pass, int port=1521)
tuple conn
Definition: results_mgr.py:53