How to connect with oracle occi C++ library to a docker container?
I can connect with a user I created in an oracle 23 free db in a docker container with
<code>sqlplus dbusername/password@localhost:1521/freepdb1
SQL*Plus: Release 23.0.0.0.0 - for Oracle Cloud and Engineered Systems on Mon Dec 9 09:25:08 2024
Version 23.6.0.24.10
Copyright (c) 1982, 2024, Oracle. All rights reserved.
Last Successful login time: Mon Dec 09 2024 09:14:52 +01:00
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.5.0.24.07
SQL> SELECT version FROM PRODUCT_COMPONENT_VERSION
WHERE product LIK 2 E 'Oracle Database%';
VERSION
--------------------------------------------------------------------------------
23.0.0.0.0
</code>
<code>sqlplus dbusername/password@localhost:1521/freepdb1
SQL*Plus: Release 23.0.0.0.0 - for Oracle Cloud and Engineered Systems on Mon Dec 9 09:25:08 2024
Version 23.6.0.24.10
Copyright (c) 1982, 2024, Oracle. All rights reserved.
Last Successful login time: Mon Dec 09 2024 09:14:52 +01:00
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.5.0.24.07
SQL> SELECT version FROM PRODUCT_COMPONENT_VERSION
WHERE product LIK 2 E 'Oracle Database%';
VERSION
--------------------------------------------------------------------------------
23.0.0.0.0
</code>
sqlplus dbusername/password@localhost:1521/freepdb1
SQL*Plus: Release 23.0.0.0.0 - for Oracle Cloud and Engineered Systems on Mon Dec 9 09:25:08 2024
Version 23.6.0.24.10
Copyright (c) 1982, 2024, Oracle. All rights reserved.
Last Successful login time: Mon Dec 09 2024 09:14:52 +01:00
Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.5.0.24.07
SQL> SELECT version FROM PRODUCT_COMPONENT_VERSION
WHERE product LIK 2 E 'Oracle Database%';
VERSION
--------------------------------------------------------------------------------
23.0.0.0.0
The docker container was created such that
<code>$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
629de2771f43 container-registry.oracle.com/database/free:latest "/bin/bash -c $ORACL…" 5 days ago Up 8 minutes (healthy) 0.0.0.0:1521->1521/tcp, :::1521->1521/tcp oradb
</code>
<code>$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
629de2771f43 container-registry.oracle.com/database/free:latest "/bin/bash -c $ORACL…" 5 days ago Up 8 minutes (healthy) 0.0.0.0:1521->1521/tcp, :::1521->1521/tcp oradb
</code>
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
629de2771f43 container-registry.oracle.com/database/free:latest "/bin/bash -c $ORACL…" 5 days ago Up 8 minutes (healthy) 0.0.0.0:1521->1521/tcp, :::1521->1521/tcp oradb
However, this example cannot create the oracle db environment:
<code>$ cat dbconnection.cpp
#include <iostream>
#include <occi.h>
using namespace oracle::occi;
using namespace std;
int main() {
// Database connection details
string user = "dbusername";
string password = "password";
//string connectString = "localhost:1521/orapdb1";
string connectString = "localhost:1521/freepdb1";
Environment *env = nullptr;
env = Environment::createEnvironment(Environment::DEFAULT);
if(!env)
cout << "Environment created." << endl;
else
cerr << "Environment not created." << endl;
return 0;
}
</code>
<code>$ cat dbconnection.cpp
#include <iostream>
#include <occi.h>
using namespace oracle::occi;
using namespace std;
int main() {
// Database connection details
string user = "dbusername";
string password = "password";
//string connectString = "localhost:1521/orapdb1";
string connectString = "localhost:1521/freepdb1";
Environment *env = nullptr;
env = Environment::createEnvironment(Environment::DEFAULT);
if(!env)
cout << "Environment created." << endl;
else
cerr << "Environment not created." << endl;
return 0;
}
</code>
$ cat dbconnection.cpp
#include <iostream>
#include <occi.h>
using namespace oracle::occi;
using namespace std;
int main() {
// Database connection details
string user = "dbusername";
string password = "password";
//string connectString = "localhost:1521/orapdb1";
string connectString = "localhost:1521/freepdb1";
Environment *env = nullptr;
env = Environment::createEnvironment(Environment::DEFAULT);
if(!env)
cout << "Environment created." << endl;
else
cerr << "Environment not created." << endl;
return 0;
}
Build:
<code>$ g++ -o mwe dbconnection.cpp -I/path/to/oracle/instantclient_23_6/sdk/include -L/path/to/oracle/instantclient_23_6 -locci -lclntsh
</code>
<code>$ g++ -o mwe dbconnection.cpp -I/path/to/oracle/instantclient_23_6/sdk/include -L/path/to/oracle/instantclient_23_6 -locci -lclntsh
</code>
$ g++ -o mwe dbconnection.cpp -I/path/to/oracle/instantclient_23_6/sdk/include -L/path/to/oracle/instantclient_23_6 -locci -lclntsh
Run the built file:
<code>$ ./mwe
Environment not created.
</code>
<code>$ ./mwe
Environment not created.
</code>
$ ./mwe
Environment not created.