时间:2021-07-01 10:21:17 帮助过:14人阅读
#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";//通过宿主变量 指定名字 char *linkt="link2"; EXEC SQL END DECLARE SECTION; //user 用户名 //passwd 密码 //sid 数据库ID void main() { int ret=0; //连接数据库方式三 --多个用户连接多个数据库 EXEC SQL connect:user IDENTIFIED BY :passwd AT :linkf USING :sid ; if(sqlca.sqlcode!=0) { ret=sqlca.sqlcode; printf("connect1 err :%d",ret); system("pause"); }else { printf("connect1 ok!\r\n"); //提交事务断开连接 EXEC SQL commit release; printf("Oracle closed !\r\n"); //system("pause"); } EXEC SQL connect:user IDENTIFIED BY :passwd AT :linkt USING :sid ; if(sqlca.sqlcode!=0) { ret=sqlca.sqlcode; printf("connect2 err :%d",ret); system("pause"); }else { printf("connect2 ok!\r\n"); //提交事务断开连接 EXEC 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" //这里我用的是一个用户,其实也可以是多个用户 EXEC SQL BEGIN DECLARE SECTION; char *user="scott"; char *passwd="123456"; char *sid="orcl"; EXEC SQL END DECLARE SECTION; void main() { int ret=0; //和第三种方式不同,由oracle自动分配 EXEC SQL DECLARE linkf DATABASE; EXEC SQL DECLARE linkt DATABASE; //连接数据库方式四 --注意linkf不再是宿主变量,所以不需要加: EXEC SQL connect:user IDENTIFIED BY :passwd AT linkf USING :sid ; if(sqlca.sqlcode!=0) { ret=sqlca.sqlcode; printf("connect1 err :%d",ret); system("pause"); }else { printf("connect1 ok!\r\n"); //提交事务断开连接 EXEC SQL commit release; printf("Oracle closed !\r\n"); //system("pause"); } EXEC SQL connect:user IDENTIFIED BY :passwd AT linkt USING :sid ; if(sqlca.sqlcode!=0) { ret=sqlca.sqlcode; printf("connect2 err :%d",ret); system("pause"); }else { printf("connect2 ok!\r\n"); //提交事务断开连接 EXEC SQL commit release; printf("Oracle closed !\r\n"); //system("pause"); } system("pause"); }
数据库 Proc编程二
标签:分配 使用 can war crt blog close std connect