Database proc Programming Two

Source: Internet
Author: User

#define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>#include<string.h>#include"sqlca.h"//connecting to a database/*EXEC SQL CONNECT {: User identified by:oldpswd |: USR_PSW} [[at {dbname |: host_variable}] Using:connect_strin G] [{ALTER authorization:newpswd | in {SYSDBA |        Sysoper} MODE}]; */EXEC SQL BEGIN DECLARE section; Char* serverid="Scott/[email protected]"; Charuser[ +]; Charpasswd[ +]; Charsid[ +]; EXEC SQL END DECLARE section;//User username//passwd Password//SID Database IDvoidMain () {intret=0; //using host variables in the C language//printf ("serverid=%s\r\n", ServerID);printf ("User:"); scanf ("%s", user); printf ("passwd:"); scanf ("%s", passwd); printf ("SID:"); scanf ("%s", sid); //How to connect to a database-- using variables in Embedded SQL programming is added: EXEC SQL Connect:user identified by:p asswd Using:sid; //Connect database Mode two//EXEC SQL Connect:serverid;    if(sqlca.sqlcode!=0) {ret=Sqlca.sqlcode; printf ("Connect err:%d", ret); System ("Pause"); }Else{printf ("Connect ok!\r\n"); //COMMIT Transaction DisconnectEXEC SQL commit release; printf ("Oracle closed!\r\n"); System ("Pause"); }}
#define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>#include<string.h>#include"sqlca.h"EXEC SQL BEGIN DECLARE section; Char*user="Scott"; Char*passwd="123456"; Char*sid="ORCL"; Char*linkf="Link1";//assigning names by host variables    Char*linkt="Link2"; EXEC SQL END DECLARE section;//User username//passwd Password//SID Database IDvoidMain () {intret=0; //Connect Database mode three-multiple users connect to multiple databasesEXEC SQL Connect:user identified by:p asswd AT:LINKF Using:sid; if(sqlca.sqlcode!=0) {ret=Sqlca.sqlcode; printf ("Connect1 err:%d", ret); System ("Pause"); }Else{printf ("Connect1 ok!\r\n"); //COMMIT Transaction DisconnectEXEC SQL commit release; printf ("Oracle closed!\r\n"); //System ("pause");} EXEC SQL Connect:user identified by:p asswd At:linkt Using:sid; if(sqlca.sqlcode!=0) {ret=Sqlca.sqlcode; printf ("connect2 err:%d", ret); System ("Pause"); }Else{printf ("Connect2 ok!\r\n"); //COMMIT Transaction DisconnectEXEC SQL commit release; printf ("Oracle closed!\r\n"); //System ("pause");} system ("Pause");}
#define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>#include<string.h>#include"sqlca.h"//Here I use a user, in fact, can also be a number of usersEXEC SQL BEGIN DECLARE section; Char*user="Scott"; Char*passwd="123456"; Char*sid="ORCL"; EXEC SQL END DECLARE section;voidMain () {intret=0; //different from the third way, automatically assigned by OracleEXEC SQL DECLARE LINKF DATABASE;    EXEC SQL DECLARE Linkt DATABASE; //Connect to database mode four-- note that LINKF is no longer a host variable and therefore does not need to be added: EXEC SQL Connect:user identified by:p asswd at LINKF Using:sid; if(sqlca.sqlcode!=0) {ret=Sqlca.sqlcode; printf ("Connect1 err:%d", ret); System ("Pause"); }Else{printf ("Connect1 ok!\r\n"); //COMMIT Transaction DisconnectEXEC SQL commit release; printf ("Oracle closed!\r\n"); //System ("pause");} EXEC SQL Connect:user identified by:p asswd at Linkt Using:sid; if(sqlca.sqlcode!=0) {ret=Sqlca.sqlcode; printf ("connect2 err:%d", ret); System ("Pause"); }Else{printf ("Connect2 ok!\r\n"); //COMMIT Transaction DisconnectEXEC SQL commit release; printf ("Oracle closed!\r\n"); //System ("pause");} system ("Pause");}

Database proc Programming Two

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.