반응형

관련 URL : https://mariadb.com/kb/en/library/installing-the-connect-storage-engine/

 

Installing the CONNECT Storage Engine

Installing the CONNECT storage engine.

mariadb.com

 

MariaDB 10.2 버전부터 connect engine 이 반영되었습니다.

 

CONNECT 스토리지 엔진은 MariaDB가 외부나 원격 데이터에 접근할 수 있습니다.

 

이 스토리지 엔진은 테이블 파티셔닝, MariaDB 가상 컬럼을 지원하며 ROWID, FILEID 및 SERVID와 같은 특수 컬럼을 정의할 수 있습니다.

 

0. CONNECT 스토리지 엔진 설치 여부

 

# mysql -uroot -p 접속

 

MariaDB [ (none) ] > show engines; 

 

 

위 출력 결과에 Engine 컬럼에 CONNECT가 보이지 않는다면 설치되어 있지 않은 상태입니다.

 

현재 이 글을 쓸때 10.3 버전의 최신은 10.3.19이나 버그가 발생하여 10.3.18로 다운 그레이드하여 사용합니ㅏㄷ.

 

1. 플러그인 패키지 설치

 

MariaDB를 설치할 때 레파지토리를 이미 구성하였다고 가정합니다.

 

패키지 설치를 위해 Centos 7 이하 yum / 이상 dnf 를 사용합니다.

 

아래 명령을 수행하면 설치를 위한 ha_connect.so 파일등이 로컬에 설치됩니다.

 

현재 이 문서는 Centos 7 로 수행합니다.

 

# yum install -y MariaDB-connect-engine

 

or

 

특정 버전 지정 설치 (DB 버전과 일치해야 합니다!)

# yum install -y MariaDB-connect-engine-10.3.18

 

 

2. 플러그인 설치

기본적으로 플러그인은 자동으로 설치되지 않습니다.

 

두가지 방법이 있습니다.

 

방법1. INSTALL SONAME  명령 수행하기

 

다음 명령을 통해 ha_connect 를 설치합니다.

 

# mysql -uroot -p

 

MariaDB [(none)]> install soname 'ha_connect';
Query OK, 0 rows affected (0.000 sec)

 

방법2. 환경 설정 파일(my.cnf / server.cnf) 에 추가

[mariadb]

...

plugin_load_add = ha_connect

 

설치후에는 다음과 같이 조회합니다.

 

MariaDB [(none)]> show engines;

 

Engine 컬럼에 CONNECT가 보이면 정상적으로 설치되어 해당 엔진을 사용할 수 있는 상태입니다.

 

3. 플러그인 제거

 

다음 명령을 통해 제거 할 수 있습니다.

 

MariaDB [(none)]> UNINSTALL SONAME 'ha_connect';

 

MariaDB [(none)]> show engines;

 

 

4. 종속성 설치

 

10.2 버전대에는 10.3 이후 버전대와 다르게 unixODBC 라이브러리를 별도로 설치했는거 같습니다.

현재 10.3 버전은 설치 시점에 종속성이 unixODBC라 같이 설치되었기 때문에 별도로 작업은 하지 않습니다.

 

별도 작업시에는 아래 명령을 통해 설치합니다.

 

# yum install unixODBC

 

 

5. 외부 테이블 연결

 

관련 정보 : https://mariadb.com/kb/en/library/connect-table-types/

 

CONNECT Table Types

 

mariadb.com

위의 내용 중 

 

CONNECT MYSQL Table Type: Accessing MySQL/MariaDB Tables

 

부분을 살펴보겠습니다.

 

A Maria 10.4 DB서버 : 192.168.10.191

B Maria 10.3 DB서버 : 192.168.10.194

 

B 서버에서 A서버 test 데이터베이스에 json_test 테이블을 Connect 하겠습니다.

 

※ 무한 루프를 피하기 위해 MYSQL 본인 자체를 참조하지 않도로 주의하세요!

 

※ Connect는 BLOC or TEXT 컬럼은 지원하지 않습니다. 

ERROR 1163 (42000): Storage engine CONNECT doesn't support BLOB/TEXT columns

 

A 서버 json_test 테이블 CREATE 구문

 

CREATE TABLE `connect_test` (
`id` INT(11) NULL DEFAULT NULL,
`DT` DATE NULL DEFAULT NULL,
`TXT` VARCHAR(1000) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci'
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB
;

아래 INSERT 문장을 통해 3줄의 데이터를 입력합니다.

INSERT INTO connect_test VALUES (1, CURDATE(), '첫번재 입력');

INSERT INTO connect_test VALUES (2, CURDATE(), '두번재 입력');

INSERT INTO connect_test VALUES (3, CURDATE(), '세번재 입력');

 

COMMIT;

 

 

B 서버에 test 데이터베이스에 new_connect_test를  아래와 같이 명령어를 입력하여 적용합니다.

CREATE TABLE test.`new_connect_test` ( 
`id` INT(11) NULL DEFAULT NULL, 
`DT` DATE NULL DEFAULT NULL, 
`TXT` VARCHAR(1000) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci' 

COLLATE='utf8_unicode_ci' 
ENGINE=CONNECT

table_type=mysql

dbname=test
tabname=connect_test
connection='mysql://root:비밀번호@192.168.10.191'

table_type : Mariadb / mysql 일 때 명시

dbname : 원본(A DB 서버) 데이터베이스 명

tabname : 원본(A DB 서버) 테이블 명

 

아래 실행 결과와 같이 오류가 발생하지 않으면 정상적으로 데이터가 조회됩니다.

 

조회

 

위와 같이 연결된 상태에서 A원본 서버에 데이터를 한건 지우고 나면 B 서버에서도 동일하게 한건 지워진 상태로 조회됩니다.

 

또한 B서버에서 new_connect_test 에 데이터를 입력/삭제하여도 동일하게 원본서버에 connect_test 테이블도 변경됩니다.

 

좀더 상세한 것은 아래 링크를 참조하면 됩니다.

 

https://mariadb.com/kb/en/library/connect-mysql-table-type-accessing-mysqlmariadb-tables/

 

CONNECT MYSQL Table Type: Accessing MySQL/MariaDB Tables

Accessing a MySQL or MariaDB table or view

mariadb.com

 

반응형

'Database > MYSQL' 카테고리의 다른 글

MariaDB JSON 컬럼 및 함수들  (0) 2019.11.04
MariaDB 테이블 백업 및 복구  (0) 2019.11.01
MariaDB 우편번호 Import 하기  (0) 2019.11.01
MariaDB SHA2 512 방식으로 암호화 예제  (0) 2019.10.25
Mysql & MariaDB 튜닝 쉘  (0) 2019.08.14
반응형

 

XRDP란 오픈소스인 Remote Desktop Protocol Server를 말합니다.

 

즉, 윈도우즈 머신로부터 당신의 리눅스 서버까지 RDP를 통해 접속가능합니다.

=> MSTSC를 통한 접속이 가능합니다.

 

 

CENTOS 7로 XRDP를 통한 접속을 위한 설치 방식을 설명합니다.

 

사전 준비 :

 

1. 사전에 CENTOS 7에 GNOME를 설치하세요

 

(관련 URL : http://www.itzgeek.com/how-tos/linux/centos-how-tos/install-gnome-gui-on-centos-7-rhel-7.html)

 

 

설정:

 

1. 저장소를 신규로 설정합니다.

 

# vi /etc/yum.repos.d/xrdp.repo 

 

위의 파일 안에 다음의 내용을 입력합니다.

[xrdp]
name=xrdp
baseurl=http://li.nux.ro/download/nux/dextop/el7/x86_64/
enabled=1
gpgcheck=0 

 

 

설치:

1. 다음의 명령을 실행하여 위의 선언한 xrdp 저장소로부터 읽어들여 설치합니다.

 

# yum -y install xrdp tigervnc-server

 

 

다음과 같은 결과가 나오면서 새로 생성된 저장소로 부터 패키지를 가지고 오고 있는지 확인하십시오

 

 --> Running transaction check
---> Package xrdp.x86_64 0:0.6.1-2.el7.nux will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
Package        Arch             Version                   Repository      Size
================================================================================
Installing:
xrdp           x86_64           0.6.1-2.el7.nux           xrdp           271 k
 
Transaction Summary
================================================================================
Install  1 Package
 
Total download size: 271 k
Installed size: 1.5 M
Is this ok [y/d/N]
Downloading packages:
xrdp-0.6.1-2.el7.nux.x86_64.rpm                            | 271 kB   00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : xrdp-0.6.1-2.el7.nux.x86_64                                  1/1
Verifying  : xrdp-0.6.1-2.el7.nux.x86_64                                  1/1
 
Installed:
xrdp.x86_64 0:0.6.1-2.el7.nux

 

 

설치가 완료되면 XRDP 서비스를 시작합니다

# systemctl start xrdp.service 

 

 

xrdp는 기본 3389 포트를 사용합니다.

※ 만약 변경하고자 할때는 /etc/xrdp/xrdp.ini의 port의 값을 변경하면 됩니다.

 

서비스가 동작중인지 확인합니다.(아래는 3389로 동작하고 있음)

 

 # netstat -antup | grep xrdp
tcp 0 0 0.0.0.0:3389 0.0.0.0:* LISTEN 1508 / xrdp
tcp 0 0 127.0.0.1:3350 0.0.0.0:* LISTEN 1507 / xrdp-sesman

 

CENTOS 7에서는 기본적으로 재부팅후에 자동으로 서비스가 시작되지 않습니다.

따라서 아래와 같은 명령을 통해 자동 시작기능을 설정합니다.

# systemctl enable xrdp.service 

 

외부 기기에서 rdp 연결을 허용하는 iptables 규칙을 작성하는 것입니다. (tcp 3389 포트를 예외로 설정함)

# firewall-cmd --permanent --zone=public --add-port=3389/tcp
# firewall-cmd --reload 

 

SELinux 구성

# chcon --type=bin_t /usr/sbin/xrdp
# chcon --type=bin_t /usr/sbin/xrdp-sesman 

 

 

테스트 :

 

아래와 같이 mstsc를 통한 대상 서버 접속을 합니다.

 

CentOS 7 - xrdp MSTSC

 

 

사용자 이름과 암호를 입력하라는 메시지가 표시됩니다. root 또는 시스템에있는 사용자를 사용할 수 있습니다. "sesman-Xvnc"모듈을 사용해야합니다.

 

CentOS 7 - xrdp 로그인 페이지

 

확인을 클릭하면 처리가 표시됩니다. 30 분 안에 데스크 탑을 연결을 얻게 됩니다.

 

CentOS 7 - xrdp 데스크탑

 

 

 

 

출처 : http://www.itzgeek.com/how-tos/linux/centos-how-tos/install-xrdp-on-centos-7-rhel-7.html

반응형

'OS > Linux' 카테고리의 다른 글

Centos 7 SAMBA 설정  (1) 2019.09.05
vi 색상 표기  (0) 2019.05.08
리눅스 백업 및 복구  (0) 2013.01.25
삼성 컴퓨터 유분투 설치기.  (0) 2012.02.06
rkhunter (리눅스 침입 탐지 사용하기)  (1) 2010.10.14
반응형


vnc-3.3.3r2-6.aix5.1.ppc.rpm


VNC 설치 오류 관련

참조 : http://thomas.patrickdepinguin.com/knowledgebase/clearcase



AIX VNC 설치 : 

http://blog.daum.net/netflow/16904684

http://hermestop.tistory.com/123


root 로 


rpm -Uvh vnc-3.3.3r2-6.aix5.1.ppc.rpm


가동은 vncserver / 중지는 kill로..


ps -ef | grep vnc 을 통해 -port 옵션이 포트 정보임.


~/.vnc 디렉토리에


xstartup 파일 변경 내역(폰트 오류 뜨는것 포함)


===============================  설정 시작 ===================================



#!/bin/sh


xrdb $HOME/.Xresources

#xsetroot -solid grey

#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &

#twm &



export LANG=C;

export LC_ALL=C;

export LC_TYPE=C;


# This line gives you a CDE desktop when you sign on to VNC


/usr/dt/bin/dtsession &


============================== 설정 종료 =====================================


ORACLE 계정의 .profile 파일안에


export DISPLAY=localhost:1 

을 추가해야만.. xclock or dbca 등 명령어들이 상콤하게 잘 뜬다...

==============================================================================

반응형

'OS > AIX' 카테고리의 다른 글

SSHD 서버 설치  (0) 2012.11.07
AIX 서버 시간 설정 하기  (0) 2012.08.06
AIX 칩입 확인 해보자 !  (0) 2011.03.23
IBM JVM -Xloratio 옵션  (0) 2011.03.03
날짜 관련 얻기  (0) 2011.03.02
반응형

Home 초과 버젼 에서는

제어판>관리도구>로컬보안정책>로컬정책>보안옵션>네트워크보안 LAN Manager 에서

“LM 및 NTLM 응답보내기” 로 설정

물론... 보안정책은 secpol.msc 명령을 통해 한번에 고고싱도 가능함.



Home 버젼에서는...

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa

32bit Dword 값으로 LmCompatibilityLevel  생성후

값을 1로 세팅한다.(관련 레지스트리는 파일 첨부)

반응형

'Windows' 카테고리의 다른 글

윈도우즈 업데이트 오류  (0) 2012.02.15
Windows Dump 분석하기  (0) 2012.01.20
윈도우 7 정품인증  (0) 2011.04.22
터미널 서비스 포트 변경 방법  (0) 2011.01.03
XP에서 Mac 주소 변경하기  (0) 2010.12.06
반응형

http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html



Oracle Database 10g Release 2 JDBC Drivers


You must accept the OTN Development and Distribution License Agreement to download this software.
Accept License Agreement | Decline License Agreement

Oracle Database 10g Release 2 (10.2.0.5) JDBC Drivers

 JavaDoc (4,383,404 bytes)
 README
 
JDBC Thin for All Platforms
 classes12.jar (1,621,582 bytes) - for use with JDK 1.2 and JDK 1.3
 classes12_g.jar (2,070,298 bytes) - same as classes12.jar, except that classes were compiled with "javac -g" and contain some tracing information.
 classes12dms.jar (1,629,454 bytes) - same as classes12.jar, except that it contains additional code`to support Oracle Dynamic Monitoring Service.
 classes12dms_g.jar (2,078,718 bytes) - same as classes12dms.jar except that classes were compiled with "javac -g" and contain some tracing information.
 ojdbc14.jar (1,569,316 bytes) - classes for use with JDK 1.4 and 1.5
 ojdbc14_g.jar (1,965,422 bytes) - same as ojdbc14.jar, except that classes were compiled with "javac -g" and contain some tracing information.
 ojdbc14dms.jar (1,576,882 bytes) - same as ojdbc14.jar, except that it contains additional code`to support Oracle Dynamic Monitoring Service.
 ojdbc14dms_g.jar (1,973,634 bytes) - same as ojdbc14dms.jar, except that classes were compiled with "javac -g" and contain some tracing information.
 demo.tar (604,160 bytes) - contains sample JDBC programs.
 
Note: For platform specific JDBC-OCI libraries See Instant Client


Oracle Database 10g Release 2 (10.2.0.4) JDBC Drivers

 JavaDoc (4,383,404 bytes)
 README
 
JDBC Thin for All Platforms
 classes12.jar (1,609,607 bytes) - for use with JDK 1.2 and JDK 1.3
 classes12_g.jar (2,055,921 bytes) - same as classes12.jar, except that classes were compiled with "javac -g" and contain some tracing information.
 classes12dms.jar (1,617,382 bytes) - same as classes12.jar, except that it contains additional code`to support Oracle Dynamic Monitoring Service.
 classes12dms_g.jar (2,064,313 bytes) - same as classes12dms.jar except that classes were compiled with "javac -g" and contain some tracing information.
 ojdbc14.jar (1,555,682 bytes) - classes for use with JDK 1.4 and 1.5
 ojdbc14_g.jar (1,950,033 bytes) - same as ojdbc14.jar, except that classes were compiled with "javac -g" and contain some tracing information.
 ojdbc14dms.jar (1,563,375 bytes) - same as ojdbc14.jar, except that it contains additional code`to support Oracle Dynamic Monitoring Service.
 ojdbc14dms_g.jar (1,958,237 bytes) - same as ojdbc14dms.jar, except that classes were compiled with "javac -g" and contain some tracing information.
 orai18n.jar (1,646,178 bytes) - NLS classes for use with JDK 1.2, 1.3, 1.4, and 1.5. This jar file replaces the old nls_charset jar/zip files.
 demo.tar (604,160 bytes) - contains sample JDBC programs.
 
Note: For platform specific JDBC-OCI libraries See Instant Client


Oracle Database 10g Release 2 (10.2.0.3) JDBC Drivers

 JavaDoc (4,383,404 bytes)
 README
 
JDBC Thin for All Platforms
 classes12.jar (1,600,090 bytes) - for use with JDK 1.2 and JDK 1.3
 classes12_g.jar (2,044,594 bytes) - same as classes12.jar, except that classes were compiled with "javac -g" and contain some tracing information.
 classes12dms.jar (1,607,745 bytes) - same as classes12.jar, except that it contains additional code`to support Oracle Dynamic Monitoring Service.
 classes12dms_g.jar (2,052,968 bytes) - same as classes12dms.jar except that classes were compiled with "javac -g" and contain some tracing information.
 ojdbc14.jar (1,545,954 bytes) - classes for use with JDK 1.4 and 1.5
 ojdbc14_g.jar (1,938,906 bytes) - same as ojdbc14.jar, except that classes were compiled with "javac -g" and contain some tracing information.
 ojdbc14dms.jar (1,553,561 bytes) - same as ojdbc14.jar, except that it contains additional code`to support Oracle Dynamic Monitoring Service.
 ojdbc14dms_g.jar (1,947,136 bytes) - same as ojdbc14dms.jar, except that classes were compiled with "javac -g" and contain some tracing information.
 orai18n.jar (1,645,114 bytes) - NLS classes for use with JDK 1.2, 1.3, 1.4, and 1.5. This jar file replaces the old nls_charset jar/zip files.
 ons.jar (48,492 bytes) - for use by the pure Java client-side Oracle Notification Services (ONS) deamon.
 demo.tar (604,160 bytes) or demo.zip (529,267 bytes) - contains sample JDBC programs.
 
Note: For platform specific JDBC-OCI libraries See Instant Client


Oracle Database 10g Release 2 (10.2.0.2) JDBC Drivers

 JavaDoc (4,383,404 bytes)
 README
 
JDBC Thin for All Platforms
 classes12.jar (1,594,191 bytes) - for use with JDK 1.2 and JDK 1.3 
 classes12_g.jar (2,038,127 bytes) - same as classes12.jar, except that classes were compiled with "javac -g" and contain some tracing information. 
 classes12dms.jar (1,601,843 bytes) - same as classes12.jar, except that it contains additional code`to support Oracle Dynamic Monitoring Service. 
 classes12dms_g.jar (2,046,467 bytes) - same as classes12dms.jar except that classes were compiled with "javac -g" and contain some tracing information.
 ojdbc14.jar (1,540,457 bytes) - classes for use with JDK 1.4 and 1.5
 ojdbc14_g.jar (1,932,834 bytes) - same as ojdbc14.jar, except that classes were compiled with "javac -g" and contain some tracing information. 
 ojdbc14dms.jar (1,548,006 bytes) - same as ojdbc14.jar, except that it contains additional code`to support Oracle Dynamic Monitoring Service. 
 ojdbc14dms_g.jar (1,940,478 bytes) - same as ojdbc14dms.jar, except that classes were compiled with "javac -g" and contain some tracing information.
 orai18n.jar (1,645,109 bytes) - NLS classes for use with JDK 1.2, 1.3, 1.4, and 1.5. This jar file replaces the old nls_charset jar/zip files. 
 ons.jar (48,492 bytes) - for use by the pure Java client-side Oracle Notification Services (ONS) deamon.
 demo.tar (604,160 bytes) or demo.zip (529,267 bytes) - contains sample JDBC programs.
 
Note: For platform specific JDBC-OCI libraries See Instant Client



Oracle Database 10g Release 2 (10.2.0.1.0) JDBC Drivers

 JavaDoc (4,383,404 bytes)
 README
 
JDBC Thin for All Platforms
 classes12.jar (1,590,491 bytes) - for use with JDK 1.2 and JDK 1.3 
 classes12_g.jar (2,033,507 bytes) - same as classes12.jar, except that classes were compiled with "javac -g" and contain some tracing information. 
 classes12dms.jar (1,598,183 bytes) - same as classes12.jar, except that it contains additional code`to support Oracle Dynamic Monitoring Service. 
 classes12dms_g.jar (2,041,904 bytes) - same as classes12dms.jar except that classes were compiled with "javac -g" and contain some tracing information.
 ojdbc14.jar (1,536,979 bytes) - classes for use with JDK 1.4 and 1.5
 ojdbc14_g.jar (1,928,714 bytes) - same as ojdbc14.jar, except that classes were compiled with "javac -g" and contain some tracing information. 
 ojdbc14dms.jar (1,544,468 bytes) - same as ojdbc14.jar, except that it contains additional code`to support Oracle Dynamic Monitoring Service. 
 ojdbc14dms_g.jar (1,936,765 bytes) - same as ojdbc14dms.jar, except that classes were compiled with "javac -g" and contain some tracing information.
 orai18n.jar (1,551,155 bytes) - NLS classes for use with JDK 1.2, 1.3, 1.4, and 1.5. This jar file replaces the old nls_charset jar/zip files. 
 ons.jar (48,492 bytes) - for use by the pure Java client-side Oracle Notification Services (ONS) deamon.
 demo.tar (604,160 bytes) or demo.zip (529,267 bytes) - contains sample JDBC programs.
 
Note: For platform specific JDBC-OCI libraries See Instant Client

반응형
반응형


- 이클립스 상에서 오라클 DATABASE를 바로 연결하여 사용하는 방법을 기술한다.

설치에 사용된 이클립스...




Help -> SoftWare Update를 클릭


1. Add Site를 누름 

2.http://quantum.sourceforge.net/update-site/ (Location) 부분에 입력

3. OK를 클릭

4. Quantum 을 검색 한뒤

5. Install 버튼 클릭



6. NEXT를 클릭


7. 사용 조건에 승인하고 Finish 를 클릭 -> 설치 완료
  
    - 아래와 같이 설치가 완료되어 다시 시작한다는 메시지가 뜨면 YES를 누르고 이클립스를 다시 시작함.
  


8. 이클립스 상에서 Quantum 플러그인 추가

window -> open Perspective -> other



9. Other open Perspective 화면에서 Quantum DB를 선택함.


10. 정상적으로 설치되었음을 확인할 수 있다.(연결정보 설정은 당연히 현재는 안되어 있음)

11. 연결 정보를 다음과 같이 추가함.
Database Bookmarks 탭상에서 빈공간에서 마우스 우클릭 -> New Bookmark... 클릭


12.  ADD driver을 눌러 추가하자 ! (우리는 오라클을 추가할 것이다.)



13. Add External Jar.. 늘 눌러 ojbc14.jar를 추가함.


14. 아래와 같이 정보를 설정하고 Finish를 누름



15. 입력한 Oracle 드라이버를 선택후 Next> 를 클릭


16. 다음과 같이 DB 연결 정보를 입력
     userid : 연결ID
     passwd : 연결ID의 암호
     HOSTNAME : DB서버 주소
     PORT : 오라클 리스너 포트(일반적으로 1521)
     DATABASE NAME : SID NAME


17. 북마크에서 사용할 이름을 지정함


18. 17번까지의 설정을 모두 마치면 자동으로 연결되고(정보가 틀리지 않았다면)
     Quantum SQL Queries View상에서 쿼리를 입력후 초록색 ▶ 버튼을 누르면 하단의 Quantum Table View 상에서 데이터가 조회됨.





P.$ :
1. MySql 연결시에는 mysql-connector-java-5.1.6-bin.jar 파일을 다운받음
2. 드라이버 선택 -> com.mysql.jdbc.Driver
3. 연결 포트는 3306임.
반응형
반응형
Oracle C++ Call Interface (OCCI) is an Application Programming Interface (API) that provides C++ applications access to data in an Oracle database. This API is a significant improvement to the Oracle Call Interface (OCI) API as far as ease of use is concerned. Engineers who have written JDBC (Java Database Connectivity) code will find the OCCI API to be quite similar to that of JDBC

1) The table that is used in the example code is:

Code: SQL
CREATE TABLE EMP(
    empno     NUMBER,
    ename     VARCHAR2(10),
    hireDate  Date);
2) Database Query : Select the contents of the EMP table

Code: Cpp
#include <DbManager.h>
#include <iostream>

using namespace std;

using namespace oracle::occi;

const string sqlString("select empno, ename, hiredate from emp");

const string dateFormat("DD-MON-YYYY HH24:MI:SS");

int main(int argc, char **argv)

{
    if (argc != 2)
    {
        cerr << "\nUsage: " << argv[0] << " <db-user-name>\n" << endl;
        exit(1);
    }
   
    // Initialize OracleServices
   
    DbManager* dbm = NULL;
   
    OracleServices* oras = NULL;
   
    Statement *stmt = NULL;
   
    ResultSet *resultSet = NULL;
   
    try
    {
       
        // Obtain OracleServices object with the default args.
       
        dbm = new DbManager(userName);
       
        oras = dbm->getOracleServices();
       
        // Obtain a cached connection
       
        Connection * conn = oras->connection();
       
        // Create a statement
       
        stmt = conn->createStatement(sqlString);
       
        int empno;
       
        string ename;
       
        Date hireDate;
       
        string dateAsString;
       
        // Execute query to get a resultset
       
        resultSet = stmt->executeQuery();
       
        while (resultSet->next())
        {
           
            empno = resultSet->getInt(1)// get the first column returned by the query;
           
            ename = resultSet->getString(2)// get the second column returned by the query
           
            hireDate = resultSet->getDate(3)// get the third column returned by the query
           
            dateAsString="";
           
            //You cannot check for null until the data has been read
           
            if (resultSet->isNull(1))
            {
                cout << "Employee num is null... " << endl;
            }
            if (resultSet->isNull(2))
            {
                cout << "Employee name is null..." << endl;
            }
            if (resultSet->isNull(3))
            {
                cout << "Hire date is null..." << endl;
            }
            else
            {
                dateAsString=hireDate.toText(dateFormat);
            }
            cout << empno << "\t" << ename << "\t" << dateAsString << endl;
           
        }
       
        // Close ResultSet and Statement
       
        stmt->closeResultSet(resultSet);
       
        conn->terminateStatement(stmt);
       
        // Close Connection and OCCI Environment
       
        delete dbm;
       
    }
    catch (SQLException& ex)
    {
        if (dbm != NULL)
        {
            dbm->rollbackActions(ex, stmt, resultSet); // free resources and rollback transaction
        }
    }
    catch (ExoException& ex1)
    {
        cerr << "\nCaught ExoException:\n" << ex1.getExceptionText() << endl;
        exit(2);
    }
   
    return 0;
}

반응형

+ Recent posts