Connect Pro * C to a remote ORACLE database instance

Source: Internet
Author: User

I recently learned how to use proc for Oracle application development. However, I did not have much detail about this on the Internet. After some twists and turns, I finally completed a test case.

The function implemented by the program is very simple. By accessing a remote ORACLE database, a field is read, returned, and displayed. As I am a beginner and have limited capabilities, I hope I can help you with some beginners.

Preparations: Install the Oracle client, set the corresponding environment variables, and configure TNS ($ ORACLE_HOME/Network/admin/tnsnames. ora)

Main steps: Use proc to compile a. PC file -----> Use proc to pre-compile ----> Generate a. c file ------> Generate an executable file for CC/GCC Compilation

The specific file content is as follows:

Conn. PC File

# Include <stdio. h> # include <stdlib. h> exec SQL begin declare section; char userid [20] = "***/***"; /* username/password */Char remotedb [20] = "***";/* servername In the TNS corresponding to the remote database, see TNS configuration */Char data [2]; exec SQL end declare section; Exec SQL include sqlca; void sqlerror (); int main () {exec SQL whenever sqlerror do sqlerror (); Exec SQL CONNECT: userid using: remotedb; exec SQL select test into: Data from temp where serial_num BER = '1'; Exec SQL commit work release; printf ("datebase data: \ t % s \ n", data); exit (0);} void sqlerror () {exec SQL whenever sqlerror continue; Exec SQL rollback work release; printf ("----- Pro * C connect error! ---- N "); exit (-1 );}

Below is the MAKEFILE file, which was found online. It was simply modified and I would like to thank you first.

ORACLE_HOME=/oracle/product/10.2/db_1INCLDIR= -I. -I$ORACLE_HOME/precomp/public -I$ORACLE_HOME/rdbms/public -I$ORACLE_HOME/rdbms/demo -I$ORACLE_HOME/plsql/public -I$ORACLE_HOME/network/public DFLAGS= -DPRECOMP -DLINUX -D_GNU_SOURCE -DSLTS_ENABLE -DSLMXMX_ENABLE -D_REENTRANT -DNS_THREADSCFLAGS= -O3LIBPATH= -L$ORACLE_HOME/lib/LIBS=-lclntsh  -ldl -lmconn:conn.pc        proc parse=no iname=conn.pc include=$(ORACLE_HOME)/precomp/public        cc  -o $@ $@.c -I$(ORACLE_HOME)/precomp/public -L$(ORACLE_HOME)/lib -lclntsh -lclient10 $(LIBPATH) $(LIBS)clean:        rm *.lis conn.c conn 

Execute make

Generate the corresponding. c file and executable file Conn

Run./Conn

Display

Datebase data: 5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.