Tutorials (upcoming v5.0.0)

Sample Applications

Minimal OCILIB C application

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    #include "ocilib.h"
    
    int main(int argc, char *argv[])
    {
        OCI_Environment* env;
        OCI_Connection* cn;
        OCI_Statement* st;
        OCI_Resultset* rs;
         
        env = OCI_EnvironmentCreate(NULL, NULL, OCI_ENV_DEFAULT);
     
        cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
        st = OCI_StatementCreate(cn);
       
        OCI_StatementExecute(st, "select intcol, strcol from table");
        
        rs = OCI_StatementGetResultset(st);
       
        while (OCI_ResultsetFetchNext(rs))
        {
            printf("%i - %s\n", OCI_ResultsetGetInt(rs, 1), OCI_ResultsetGetString(rs, 2));
        }
     
        OCI_StatementFree(st);
        OCI_ConnectionFree(cn);
        OCI_EnvironmentFree(env);
     
        return EXIT_SUCCESS;
    }

Minimal OCILIB C++ application

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    #include "ocilib.hpp"
    
    using namespace ocilib;
    
    int main(void)
    {
        try
        {
            Environment env;
    
            Connection con("db", "usr", "pwd");
            
            Statement st(con);
            st.Execute("select intcol, strcol from table");
    
            Resultset rs = st.GetResultset();
            while (rs.Next())
            {
                std::cout << rs.Get<int>(1) << " - " <<  rs.Get<ostring>(2) << std::endl;
            }
        }
        catch(std::exception &ex)
        {
             std::cout << ex.what() << std::endl;
        }
     
        return EXIT_SUCCESS;
    }