Tong Quan Ve Occi

  • Published on
    27-Nov-2014

  • View
    118

  • Download
    2

Embed Size (px)

Transcript

GII THIU V M HINH OCCII.

Tng quan v OCCI:

OCCI vit tt cua Oracle C++ Call Interface la giao din lp trinh ng dung (API) cung cp cho ng dung c++ truy cp d liu Oracle. Occi cho phep lp trinh c++ co th truy vn vn sa dung cu lnh SQL truy vn va x ly i tng. -

Nng cao hiu sut lam vic cua ng dung thng qua quan ly b nh h thng va kt ni mang. M rng ng dung phuc vu cho nhiu ngi. H tr toan din cho ng dung bng cach s dung Oracle bao gm ca phia client truy cp ti Oracle. Quan ly kt ni. Giao din nht quan cho quan ly kt ni,quan ly transaction linh ng trong mi trng client/server hoc mi trng a lung. Cung cp th vin chun truy cp csdl

-

-

Li ich cua vic s dung OCCI-

OCCI cung cp nhng li th ng k so vi cc phng php khc truy cp vo c s d liu Oracle. Thuc y lp trinh c++ va cac m hinh lp trinh hng i tng. D dang s dung D dang vi nhng ngi a quen vi JDBC. Giao din d thao tac ,i tng csdl do ngi dung inh nghia.

-

II. CU HINH OCCI TRN LINUX S DUNG NETBEAN FOR C++ Phn mm yu cu 1. Cng c : IDE: netbean 6.9.1 for c++ (tuy phin bn ) + JDK .link 2. Th vin :

Dowload 2 file trn trang Oracle.com

instantclient-basic-linux32-11.2.0.2.0.zip instantclient-sdk-linux32-11.2.0.2.0.zip

lu (khi download th phi download cho cng 1 phin bn) Mc ch cung cp th vin h tr OCCI l cc file .h v file .so 3. Hng dn cai t v cu Hnh 3.1. Ci t netbean full().

Cai t full cho chng trinh trong qua trinh cai t Netbean h tr lun trinh bin dich GNU(gcc,g++,gdb,gmake,as,gfortran). Sau khi cai t m netbean ln vao tools\option\builtool co thy GNU(trong toolcolection la okie). Th tao 1 chng trinh hello world u tin nu build thanh cng thi coi nh qua trinh cai t thanh cng tip theo. 3.2. Cu Hinh OCCI trn netbean

M netbean ln vao File\New project the categories chon c\c++ project chon c\c++ Application Nhn Next . t tn project la gi tuy y , y t la ConnecttoOracle nhn finish .ok CU HINH : Giai nen 2 file va download trn.

instantclient-basic-linux32-11.2.0.2.0.zip instantclient-sdk-linux32-11.2.0.2.0.zip

tao 1 folder mi vi du la /home/LIBOCCI/ mc dinh khi giai nen 2 file trn vao folder va tao ra thi no co tn la instantclient_11_2 khi o ng dn tham chiu ti file la /home/LIBOCCI/instantclient_11_2.

Sau o ta cn i tn 2 file th vin trong th muc va giai nen ra v ung inh dang th vin chun la. libocci.so.11.1-> libocci.so libclntsh.so.11.1-> libclntsh.so Ok tr lai man hinh IDE cua netbean . click chut vao tn project chon properties Ca s project properties xut hin ,vao muc categories chon c++ compiler Trn muc configuration chon Genaral\Include directories click add chon ng dn la /home/LIBOCCI/instantclient_11_2/sdk/include(Th muc giai nen 2 file cung cp th vin .h ) instantclient-basic-linux32-11.2.0.2.0.zip instantclient-sdk-linux32-11.2.0.2.0.zip nhn Ok (xong phn add header cho OCCI on netbean). Vn trn man hinh project properties trn muc categories chon the Linker\ trn the Configuration: Genaral\Additionlibrary directories chon ng dn ti /home/LIBOCCI/instantclient_11_2 nhn select \Ok xong . Vn trn the Linker Libraries\libraries nhn ...(Add Library File) chon ng dn ti th muc /home/LIBOCCI/instantclient_11_2 add 4 th vin libociei.so libclntsh.so libnnz11.so libocci.so sau khi add u 4 th vin nhn apply sau o nhn OK . xong phn cu hinh chay OCCi trn netbean . gi ban m file main.cpp cua project va tao ln dan oan code nay vao chay th okie va tra ra d liu thi coi nh thanh cng ( cng ty thi nhe nu ping c ti 192.168.2.243)

/* * File: main.cpp * Author: sangdd * * Created on April 19, 2011, 11:49 AM */

#include #include #include "occi.h"

using namespace std ;

using namespace oracle::occi; using oracle::occi::Environment; using oracle::occi::Connection;

//khai bao con tro Environment *env; Connection *conn; Statement *stm ; ResultSet *rs; string user="STS"; string pass="STS";

string connect="//192.168.2.243:1521/ORADB"; int main() { try { env=Environment::createEnvironment(Environment::DEFAULT); conn=env->createConnection(user,pass,connect); stm =conn->createStatement("SELECT * FROM STS.AUTHOR_TAB"); rs = stm->executeQuery(); while (rs ->next()) { cout getString(1)