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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Connecting to a Database<br />

duration. Opening a connection to the database for every thread would result in<br />

inefficient utilization of connections and poor performance.<br />

By employing the connection pooling feature, your application can use database<br />

management system (DBMS) functionality to manage the connections. <strong>Oracle</strong><br />

creates a small number of open connections, dynamically selects one of the free<br />

connections to execute a statement, and then releases the connection immediately<br />

after the execution. This relieves you from creating complex mechanisms to handle<br />

connections and optimizes performance in your application.<br />

Creating a Connection Pool<br />

To create a connection pool, you use the createConnectionPool method:<br />

virtual ConnectionPool* createConnectionPool(<br />

const string &poolUserName,<br />

const string &poolPassword,<br />

const string &connectString ="",<br />

unsigned int minConn =0,<br />

unsigned int maxConn =1,<br />

unsigned int incrConn =1) = 0;<br />

The following parameters are used in the previous method example:<br />

■ poolUserName: The owner of the connection pool<br />

■ poolPassword: The password to gain access to the connection pool<br />

■ connectString ="": The database name that specifies the database server to<br />

which the connection pool is related<br />

■ minConn: The minimum number of connections to be opened when the<br />

connection pool is created<br />

■ maxConn: The maximum number of connections that can be maintained by the<br />

connection pool. When the maximum number of connections are open in the<br />

connection pool, and all the connections are busy, an OCCI method call that<br />

needs a connection waits until it gets one, unless setErrorOnBusy() was called<br />

on the connection pool<br />

■ incrConn: The additional number of connections to be opened when all the<br />

connections are busy and a call needs a connection. This increment is<br />

implemented only when the total number of open connections is less than the<br />

maximum number of connections that can be opened in that connection pool<br />

The following code example demonstrates how you can create a connection pool:<br />

2-4 <strong>Oracle</strong> <strong>C++</strong> <strong>Call</strong> <strong>Interface</strong> Programmer’s <strong>Guide</strong>

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

Saved successfully!

Ooh no, something went wrong!