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.

Date Class<br />

Summary of Date Methods<br />

The following code example demonstrates a Date column value being retrieved<br />

from the database, a bind using a Date object, and a computation using a<br />

standalone Date object:<br />

/* Create a connection */<br />

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

Connection *conn = env->createConnection(user, passwd, db);<br />

/* Create a statement and associate a DML statement to it */<br />

string sqlStmt = "SELECT job-id, start_date from JOB_HISTORY<br />

where end_date = :x";<br />

Statement *stmt = conn->createStatement(sqlStmt);<br />

/* Create a Date object and bind it to the statement */<br />

Date edate(env, 2000, 9, 3, 23, 30, 30);<br />

stmt->setDate(1, edate);<br />

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

/* Fetch a date from the database */<br />

while(rset->next())<br />

{<br />

Date sd = rset->getDate(2);<br />

Date temp = sd; /*assignment operator */<br />

/* Methods on Date */<br />

temp.getDate(year, month, day, hour, minute, second);<br />

temp.setMonths(2);<br />

IntervalDS inter = temp.daysBetween(sd);<br />

.<br />

.<br />

.<br />

}<br />

Table 8–8 Date Methods<br />

Method Summary<br />

addDays() on page 8-52 Return a Date object with n days added.<br />

addMonths() on page 8-52 Return a Date object with n months added.<br />

daysBetween() on page 8-52 Return the number of days between the current Date<br />

object and the date specified.<br />

8-50 <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!