Go to the documentation of this file.00001 #include <iostream>
00002 #include <string>
00003 #include <sstream>
00004 #include <stdlib.h>
00005 #include <cstdlib>
00006 #include <stdexcept>
00007 #include "OnlineDB/Oracle/interface/Oracle.h"
00008
00009 using namespace std;
00010 using namespace oracle::occi;
00011
00012 #include "OnlineDB/EcalCondDB/interface/EcalDBConnection.h"
00013 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
00014
00015 EcalDBConnection::EcalDBConnection( string host,
00016 string sid,
00017 string user,
00018 string pass,
00019 int port )
00020 throw(std::runtime_error)
00021 {
00022 stringstream ss;
00023 try {
00024 ss << "//" << host << ":" << port << "/" << sid;
00025
00026 env = Environment::createEnvironment(Environment::OBJECT);
00027 conn = env->createConnection(user, pass, ss.str());
00028 stmt = conn->createStatement();
00029 } catch (SQLException &e) {
00030 cout<< ss.str() << endl;
00031 throw(std::runtime_error("ERROR: Connection Failed: " + e.getMessage() ));
00032 }
00033
00034 this->host = host;
00035 this->sid = sid;
00036 this->user = user;
00037 this->pass = pass;
00038 this->port = port;
00039 }
00040
00041 EcalDBConnection::EcalDBConnection( string sid,
00042 string user,
00043 string pass )
00044 throw(std::runtime_error)
00045 {
00046 try {
00047 env = Environment::createEnvironment(Environment::OBJECT);
00048 conn = env->createConnection(user, pass, sid);
00049 stmt = conn->createStatement();
00050 } catch (SQLException &e) {
00051 throw(std::runtime_error("ERROR: Connection Failed: " + e.getMessage() ));
00052 }
00053
00054 this->host = "";
00055 this->sid = sid;
00056 this->user = user;
00057 this->pass = pass;
00058 this->port = port;
00059 }
00060
00061 EcalDBConnection::~EcalDBConnection() throw(std::runtime_error) {
00062
00063 try {
00064 conn->terminateStatement(stmt);
00065 env->terminateConnection(conn);
00066 Environment::terminateEnvironment(env);
00067 } catch (SQLException &e) {
00068 throw(std::runtime_error("ERROR: Destructor Failed: " + e.getMessage() ));
00069 }
00070 }