2 Replies Latest reply: Apr 18, 2012 3:27 PM by 931292 RSS

    Сpp GCC Oracle Connection

    931292
      Hello. I am trying to connect to my Oracle DB from C++.

      I has installed

      instantclient-basic-linux

      instantclient-basiclite

      instantclient-jdbc-linux

      instantclient-sqlplus-linux

      instantclient-sdk-linux

      instantclient-odbc-linux

      instantclient-tools-linux

      I know that is not necessary, but I have no Idea, why it doesn't work



      I Have done



      export ORACLE_BASE=/usr/lib/oracle

      export ORACLE_HOME=$ORACLE_BASE/11.2/client64

      export LD_LIBRARY_PATH=$ORACLE_HOME/lib

      export PATH=$ORACLE_HOME/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:~/bin



      [root@gerrard ~]# echo "/usr/lib/oracle/11.1/client/lib"; > /etc/ld.so.conf.d/oic.conf

      [root@gerrard ~]# /sbin/ldconfig



      I Have got a very simple program.


      <blockquote><code><font size="2" face="Courier New" color="black">#include <occi.h>
      #include <iostream>
      #include <iomanip>



      <font color="#0000ff">#define</font> db_user_name <font color="#A31515">"hr"</font>
      <font color="#0000ff">#define</font> db_password <font color="#A31515">"hr"</font>
      <font color="#0000ff">#define</font> db_conn_str <font color="#A31515">"192.168.56.101:1521/@XE"</font>
      <font color="#008000">//#define db_conn_str "system" </font>

      <font color="#0000ff">using</font> <font color="#0000ff">namespace</font> oracle::occi;
      <font color="#0000ff">using</font> <font color="#0000ff">namespace</font> std;

      <font color="#0000ff">int</font> main(){
        <font color="#0000ff">try</font>{
         Environment* env = Environment::createEnvironment(Environment::OBJECT); 
        Connection* conn = env->createConnection(db_user_name, db_password, db_conn_str);
        cout<<<font color="#A31515">"HELLO"</font>;
        Statement* stmt = conn->createStatement(<font color="#A31515">"Select 1 from dual"</font>);
         ResultSet *rs = stmt->executeQuery();
         <font color="#0000ff">int</font> res = 0;
         <font color="#0000ff">while</font> (rs->next())
           {
           res = rs->getInt(1);
           }
           
         stmt->closeResultSet(rs);
        env->terminateConnection(conn);
         Environment::terminateEnvironment(env);
      }
       <font color="#0000ff">catch</font>(SQLException &sqlExcp)
        {
        cerr << sqlExcp.getErrorCode() << <font color="#A31515">" "</font> << sqlExcp.getMessage() << endl;
        }
        <font color="#0000ff">return</font> 0;
      }</font>

      <font size="1" color="gray">* This source code was highlighted with <font size="1" color="gray">Source Code Highlighter</font>.</font></code></blockquote>


      I compile it with



      g++ -o test test.cpp -I /usr/include/oracle/11.2/client64 -L /usr/lib/oracle/11.2/client64/lib/ -lclntsh -locci



      And I Get ERROR in OUTPUT



      <h3>

      alex@linux-86vr:/media/Files/Media/Programming/Cpp/GCC/BDORACLE> ./test 12514 ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

      </h3>

      Google told me that i have to find some tnsnames in my Instant Client. But I have Just



      /usr/lib/oracle/11.1/client/bin/adrci

      /usr/lib/oracle/11.1/client/bin/genezi

      /usr/lib/oracle/11.1/client/lib/libclntsh.so.11.1

      /usr/lib/oracle/11.1/client/lib/libnnz11.so

      /usr/lib/oracle/11.1/client/lib/libocci.so.11.1

      /usr/lib/oracle/11.1/client/lib/libociei.so

      /usr/lib/oracle/11.1/client/lib/libocijdbc11.so

      /usr/lib/oracle/11.1/client/lib/ojdbc5.jar

      /usr/lib/oracle/11.1/client/lib/ojdbc6.jar

      /usr/include/oracle/11.1/client/nzerror.h

      /usr/include/oracle/11.1/client/nzt.h

      /usr/include/oracle/11.1/client/occi.h

      /usr/include/oracle/11.1/client/occiAQ.h

      /usr/include/oracle/11.1/client/occiCommon.h

      /usr/include/oracle/11.1/client/occiControl.h

      /usr/include/oracle/11.1/client/occiData.h

      /usr/include/oracle/11.1/client/occiObjects.h

      /usr/include/oracle/11.1/client/oci.h

      /usr/include/oracle/11.1/client/oci1.h

      /usr/include/oracle/11.1/client/oci8dp.h

      /usr/include/oracle/11.1/client/ociap.h

      /usr/include/oracle/11.1/client/ociapr.h

      /usr/include/oracle/11.1/client/ocidef.h

      /usr/include/oracle/11.1/client/ocidem.h

      /usr/include/oracle/11.1/client/ocidfn.h

      /usr/include/oracle/11.1/client/ociextp.h

      /usr/include/oracle/11.1/client/ocikpr.h

      /usr/include/oracle/11.1/client/ocixmldb.h

      /usr/include/oracle/11.1/client/odci.h

      /usr/include/oracle/11.1/client/oratypes.h

      /usr/include/oracle/11.1/client/ori.h

      /usr/include/oracle/11.1/client/orid.h

      /usr/include/oracle/11.1/client/orl.h

      /usr/include/oracle/11.1/client/oro.h

      /usr/include/oracle/11.1/client/ort.h

      /usr/include/oracle/11.1/client/xa.h

      /usr/lib/oracle/11.1/client/lib/libclntsh.so

      /usr/lib/oracle/11.1/client/lib/libocci.so

      /usr/lib/oracle/11.1/client/lib/ottclasses.zip

      /usr/share/oracle/11.1/client/cdemo81.c

      /usr/share/oracle/11.1/client/demo.mk

      /usr/share/oracle/11.1/client/occidemo.sql

      /usr/share/oracle/11.1/client/occidemod.sql

      /usr/share/oracle/11.1/client/occidml.cpp

      /usr/share/oracle/11.1/client/occiobj.cpp

      /usr/share/oracle/11.1/client/occiobj.typ

      /usr/share/oracle/11.1/client/ott/usr/bin/sqlplus

      /usr/lib/oracle/11.1/client/bin/sqlplus

      /usr/lib/oracle/11.1/client/lib/glogin.sql

      /usr/lib/oracle/11.1/client/lib/libsqlplus.so

      /usr/lib/oracle/11.1/client/lib/libsqlplusic.so



      Can you help me, how to resolve this problem.