OCCI例子

来源:百度文库 编辑:神马文学网 时间:2024/04/29 14:14:01
Hi,
What VS version are you using? I have VS7 and I got OCCI working as:
- Download the following from Oracle site:
instantclient-sdk-win32-10.2.0.1-20050930.zip
instantclient-basic-win32-10.2.0.1-20050930.zip
- Create empty Win32 Console Project.
- Create folder myproject\src in the new project directory.
- Create myproject\src\include and myproject\src\lib
- Unzip the sdk and basic client files and copy:
-- all *.h files ftrom instantclient_10_2\sdk\include to
myproject\src\include
-- copy two libraries oci.lib and oraocci10.lib from
\instantclient_10_2 to myproject\src\lib
- Put your myproject.cpp into \myproject\src
- In the VS7 UI:
1. Project Properties -> C/C++ -> General -> Additional Include
Directories ->
add ...\myproject\src\include
2. Project Properties -> C/C++ -> Preprocessor -> Preprocessor
Definitions ->
add WIN32COMMON;_DLL;_MT to the existing value
3. Project Properties -> Linker -> General ->Additional Library
Directories ->
add ...\myproject\src\lib
4. Project Properties -> Linker -> Input -> Additional Dependencies ->
add: oci.lib msvcrt.lib msvcprt.lib oraocci10.lib
5. Project Properties -> Linker -> Input -> Ignore All Default
Libraries ->
change it to Yes(/NODEFAULTLIB)
- Copy instantclient_10_2\oci.dll and instantclient_10_2\oraocci10.dll
from the unzipped basic client directory to \myproject\Debug
Julia
I gave up with the occidml example and restarted with
the occiobj example. And guess what happened. It
worked. I can´t beleive it.
So I really don´t know what the difference of these
two example is as the only difference so far (as I
saw in the constructor of the two classes) is an extra
call in the occiobj-example. Well the parameters
are also different.
Occidml-example constructor:
occidml (string user, string passwd, string db)
{
env = Environment::createEnvironment (Environment::DEFAULT);
conn = env->createConnection (user, passwd, db);
}
Occiobj-example constructor:
occiobj (string user, string passwd, string db)
{
env = Environment::createEnvironment (Environment::OBJECT);
occiobjm (env);
con = env->createConnection (user, passwd, db);
}
If I have time again I will give the occidml another try. By far
I get along with the occiobj-example.
Thanks for all the people who helped me (or intended to).
Greetings Roman
I had all of the same problems in this thread.
What I discovered is that the reason for the problems is that MS VC++ Express likes the to bind with the newer versions of the libraries? (The 8.0 libraries for thread safety and debugging.)
I did get the examples to work with MS VC++ Express in a limited fashion.
I used the DEBUG version and I locallized the DLL to the project.
===================
After I confirmed this, I then switch machines and used MS VC++ 2003 and the exact same example worked perfectly.
Note: I did have to create a new project but I just used the link paths and the same instant client.
The example works! (Just with the 2003 version)
..DTate..
#include
#include
using namespace oracle::occi;
using namespace std;
class occidemo
{
private :
Environment *env;
Connection *conn;
Statement *stmt;
public :
occidemo(string user, string passwd, string db)
{
env = Environment::createEnvironment(Environment::OBJECT);
conn = env->createConnection(user, passwd, db);
}
~occidemo()
{
env->terminateConnection(conn);
Environment::terminateEnvironment(env);
}
void insertRow()
{
try
{
stmt = conn->createStatement("insert into author_tab(author_id, author_name) values(:id, :name)");
stmt->setInt(1, 1);
stmt->setString(2, "Brice");
stmt->executeUpdate();
}catch(SQLException e)
{
cout << "Exception thrown for insertRow" << endl;
cout << "Error number: " << e.getErrorCode() << endl;
cout << e.getMessage() << endl;
}
cout << "Insertion - Successful" << endl;
conn->terminateStatement(stmt);
}
};
int main()
{
string user = "system";
string passwd = "abc123_";
string db = "orcl";
try
{
cout << "occidemo for insert data on the table author_tab" << endl;
occidemo *demo = new occidemo(user, passwd, db);
demo->insertRow();
//cout << "OCIAttrGet with OCI_ATTR_USERNAME = " << OCIAttrGet((void*)OCI_ATTR_USERNAME, NULL, NULL, NULL, NULL, NULL) << endl;
cout << "occidemo done" << endl;
getchar();
}catch(SQLException e)
{
cerr << "Error running the demo: " << e.getMessage () << endl;
}
return 0;
}