10.12.2012 Views

Oracle C++ Call Interface Programmer's Guide

Oracle C++ Call Interface Programmer's Guide

Oracle C++ Call Interface Programmer's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Connecting to a Database<br />

Connecting to a Database<br />

You have a number of different options with regard to how your application<br />

connects to the database. These options are discussed in the following sections:<br />

■ Creating and Terminating an Environment<br />

■ Opening and Closing a Connection<br />

■ Creating a Connection Pool<br />

■ Utilizing a Shared Server Environment<br />

Creating and Terminating an Environment<br />

All OCCI processing takes place in the context of the Environment class. An OCCI<br />

environment provides application modes and user-specified memory management<br />

functions. The following code example shows how you can create an OCCI<br />

environment:<br />

Environment *env = Environment::createEnvironment();<br />

All OCCI objects created with the createxxx methods (connections, connection<br />

pools, statements) must be explicitly terminated and so, when appropriate, you<br />

must also explicitly terminate the environment. The following code example shows<br />

how you terminate an OCCI environment.<br />

Environment::terminateEnvironment(env);<br />

In addition, an OCCI environment should have a scope that is larger than the scope<br />

of any objects created in the context of the that environment. This concept is<br />

demonstrated in the following code example:<br />

const string userName = "SCOTT";<br />

const string password = "TIGER";<br />

const string connectString = "";<br />

Environment *env = Environment::createEnvironment();<br />

{<br />

Connection *conn = env->createConnection(userName, password, connectString);<br />

Statement *stmt = conn->createStatement("SELECT blobcol FROM mytable");<br />

ResultSet *rs = stmt->executeQuery();<br />

rs->next();<br />

Blob b = rs->getBlob(1);<br />

cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!