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.

Standard Statements<br />

Types of SQL Statements in the OCCI Environment<br />

Previous sections describe examples of both DDL and DML commands. For<br />

example:<br />

stmt->executeUpdate(“CREATE TABLE basket_tab<br />

(fruit VARCHAR2(30), quantity NUMBER)”);<br />

and<br />

Parameterized Statements<br />

stmt->executeUpdate(“INSERT INTO basket_tab<br />

VALUES(‘MANGOES’, 3)”);<br />

These are each an example of a standard statement in which you explicitly define<br />

the values of the statement. So, in these examples, the CREATE TABLE statement<br />

specifies the name of the table (basket_tab), and the INSERT statement stipulates<br />

the values to be inserted (‘MANGOES’, 3).<br />

You can execute the same statement with different parameters by setting<br />

placeholders for the input variables of the statement. These statements are referred<br />

to as parameterized statements because they are able to accept input from a user or<br />

program by using parameters.<br />

For example, suppose you want to execute an INSERT statement with different<br />

parameters. You first specify the statement by the setSQL method of the<br />

Statement handle:<br />

stmt->setSQL(“INSERT INTO basket_tab VALUES(:1, :2)”);<br />

You then call the setxxx methods to specify the parameters, where xxx stands for<br />

the type of the parameter. The following example invokes the setString and<br />

setInt methods to input the values of these types into the first and second<br />

parameters.<br />

To insert a row:<br />

stmt->setString(1, “Bananas”); // value for first parameter<br />

stmt->setInt(2, 5); // value for second parameter<br />

Having specified the parameters, you insert values into the row:<br />

Relational Programming 2-9

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

Saved successfully!

Ooh no, something went wrong!