当前位置: 技术问答>linux和unix
//急!在oracle7中的oci如何连接到另外一台机器的?例子好像都是连接到本机的?
来源: 互联网 发布时间:2015-02-01
本文导语: //例子如下,如何指连接到 oraclesid_192.168.0.1呢? //急!在oracle7中的oci如何连接到另外一台机器的?例子好像都是连接到本机的? #include #include #include #include Cda_Def cda; Lda_Def lda; /* set up the table */ text...
//例子如下,如何指连接到 oraclesid_192.168.0.1呢?
//急!在oracle7中的oci如何连接到另外一台机器的?例子好像都是连接到本机的?
#include
#include
#include
#include
Cda_Def cda;
Lda_Def lda;
/* set up the table */
text *dt = (text *) "DROP TABLE part_nos";
text *ct = (text *) "CREATE TABLE part_nos (partno NUMBER, description
VARCHAR2(20))";
text *cp = (text *) "
CREATE OR REPLACE PACKAGE update_parts ASn
TYPE part_number IS TABLE OF part_nos.partno%TYPEn
INDEX BY BINARY_INTEGER;n
TYPE part_description IS TABLE OF part_nos.description%TYPEn
INDEX BY BINARY_INTEGER;n
PROCEDURE add_parts (n IN INTEGER,n
descrip IN part_description,n
partno IN part_number);n
END update_parts;";
text *cb = (text *) "
CREATE OR REPLACE PACKAGE BODY update_parts ASn
PROCEDURE add_parts (n IN INTEGER,n
descrip IN part_description,n
partno IN part_number) isn
BEGINn
FOR i IN 1..n LOOPn
INSERT INTO part_nosn
VALUES (partno(i), descrip(i));n
END LOOP;n
END add_parts;n
END update_parts;";
#define DESC_LEN 20
#define MAX_TABLE_SIZE 1200
text *pl_sql_block = (text *) "
BEGINn
update_parts.add_parts(3, :description, :partno);n
END;";
text descrip[3][20] = {"Frammis", "Widget", "Thingie"};
sword numbers[] = {12125, 23169, 12126};
ub2 descrip_alen[3] = {DESC_LEN, DESC_LEN, DESC_LEN};
ub2 descrip_rc[3];
ub4 descrip_cs = (ub4) 3;
ub2 descrip_indp[3];
ub2 num_alen[3] = {
(ub2) sizeof (sword),
(ub2) sizeof (sword),
(ub2) sizeof (sword) };
ub2 num_rc[3];
ub4 num_cs = (ub4) 3;
ub2 num_indp[3];
ub1 hda[256];
main()
{
printf("Connecting to Oracle...");
if (olog(&lda, hda, "scott/tiger", -1, 0, -1, 0, -1,
OCI_LM_DEF)) {
printf("Cannot logon as scott/tiger. Exiting...n");
exit(1);
}
if (oopen(&cda, &lda, NULL, -1, -1, NULL, -1)) {
printf("Cannot open cursor, exiting...n");
exit(1);
}
/* Drop the table. */
printf("nDropping table...");
if (oparse(&cda, dt, -1, 0, 2))
if (cda.rc != 942)
oci_error();
printf("nCreating table...");
if (oparse(&cda, ct, -1, 0, 2))
oci_error();
/* Parse and execute the create package statement. */
printf("nCreating package...");
if (oparse(&cda, cp, -1, 0, 2))
oci_error();
if (oexec(&cda))
oci_error();
/* Parse and execute the create package body statement. */
printf("nCreating package body...");
if (oparse(&cda, cb, -1, 0, 2))
oci_error();
if (oexec(&cda))
oci_error();
/* Parse the anonymous PL/SQL block that calls the
stored procedure. */
printf("nParsing PL/SQL block...");
if (oparse(&cda, pl_sql_block, -1, 0, 2))
oci_error();
/* Bind the C arrays to the PL/SQL tables. */
printf("nBinding arrays...");
if (obndra(&cda, (text *) ":description", -1, (ub1 *) descrip,
DESC_LEN, VARCHAR2_TYPE, -1, descrip_indp, descrip_alen,
descrip_rc, (ub4) MAX_TABLE_SIZE, &descrip_cs, (text *) 0,
-1, -1))
oci_error();
if (obndra(&cda, (text *) ":partno", -1, (ub1 *) numbers,
(sword) sizeof (sword), INT_TYPE, -1, num_indp,
num_alen, num_rc, (ub4) MAX_TABLE_SIZE, &num_cs,
(text *) 0, -1, -1))
oci_error();
printf("nExecuting block...");
if (oexec(&cda)) oci_error();
printf("n");
if (oclose(&cda)) {
printf("Error closing cursor!n");
return -1;
}
if (ologof(&lda)) {
printf("Error logging off!n");
return -1;
}
exit(1);
}
oci_error()
{
text msg[600];
sword rv;
rv = oerhms(&lda, cda.rc, msg, 600);
printf("nn%.*s", rv, msg);
printf("Processing OCI function %sn", oci_func_tab[cda.fc]);
if (oclose(&cda))
printf("Error closing cursor!n");
if (ologof(&lda))
printf("Error logging off!n");
exit(1);
}
//急!在oracle7中的oci如何连接到另外一台机器的?例子好像都是连接到本机的?
#include
#include
#include
#include
Cda_Def cda;
Lda_Def lda;
/* set up the table */
text *dt = (text *) "DROP TABLE part_nos";
text *ct = (text *) "CREATE TABLE part_nos (partno NUMBER, description
VARCHAR2(20))";
text *cp = (text *) "
CREATE OR REPLACE PACKAGE update_parts ASn
TYPE part_number IS TABLE OF part_nos.partno%TYPEn
INDEX BY BINARY_INTEGER;n
TYPE part_description IS TABLE OF part_nos.description%TYPEn
INDEX BY BINARY_INTEGER;n
PROCEDURE add_parts (n IN INTEGER,n
descrip IN part_description,n
partno IN part_number);n
END update_parts;";
text *cb = (text *) "
CREATE OR REPLACE PACKAGE BODY update_parts ASn
PROCEDURE add_parts (n IN INTEGER,n
descrip IN part_description,n
partno IN part_number) isn
BEGINn
FOR i IN 1..n LOOPn
INSERT INTO part_nosn
VALUES (partno(i), descrip(i));n
END LOOP;n
END add_parts;n
END update_parts;";
#define DESC_LEN 20
#define MAX_TABLE_SIZE 1200
text *pl_sql_block = (text *) "
BEGINn
update_parts.add_parts(3, :description, :partno);n
END;";
text descrip[3][20] = {"Frammis", "Widget", "Thingie"};
sword numbers[] = {12125, 23169, 12126};
ub2 descrip_alen[3] = {DESC_LEN, DESC_LEN, DESC_LEN};
ub2 descrip_rc[3];
ub4 descrip_cs = (ub4) 3;
ub2 descrip_indp[3];
ub2 num_alen[3] = {
(ub2) sizeof (sword),
(ub2) sizeof (sword),
(ub2) sizeof (sword) };
ub2 num_rc[3];
ub4 num_cs = (ub4) 3;
ub2 num_indp[3];
ub1 hda[256];
main()
{
printf("Connecting to Oracle...");
if (olog(&lda, hda, "scott/tiger", -1, 0, -1, 0, -1,
OCI_LM_DEF)) {
printf("Cannot logon as scott/tiger. Exiting...n");
exit(1);
}
if (oopen(&cda, &lda, NULL, -1, -1, NULL, -1)) {
printf("Cannot open cursor, exiting...n");
exit(1);
}
/* Drop the table. */
printf("nDropping table...");
if (oparse(&cda, dt, -1, 0, 2))
if (cda.rc != 942)
oci_error();
printf("nCreating table...");
if (oparse(&cda, ct, -1, 0, 2))
oci_error();
/* Parse and execute the create package statement. */
printf("nCreating package...");
if (oparse(&cda, cp, -1, 0, 2))
oci_error();
if (oexec(&cda))
oci_error();
/* Parse and execute the create package body statement. */
printf("nCreating package body...");
if (oparse(&cda, cb, -1, 0, 2))
oci_error();
if (oexec(&cda))
oci_error();
/* Parse the anonymous PL/SQL block that calls the
stored procedure. */
printf("nParsing PL/SQL block...");
if (oparse(&cda, pl_sql_block, -1, 0, 2))
oci_error();
/* Bind the C arrays to the PL/SQL tables. */
printf("nBinding arrays...");
if (obndra(&cda, (text *) ":description", -1, (ub1 *) descrip,
DESC_LEN, VARCHAR2_TYPE, -1, descrip_indp, descrip_alen,
descrip_rc, (ub4) MAX_TABLE_SIZE, &descrip_cs, (text *) 0,
-1, -1))
oci_error();
if (obndra(&cda, (text *) ":partno", -1, (ub1 *) numbers,
(sword) sizeof (sword), INT_TYPE, -1, num_indp,
num_alen, num_rc, (ub4) MAX_TABLE_SIZE, &num_cs,
(text *) 0, -1, -1))
oci_error();
printf("nExecuting block...");
if (oexec(&cda)) oci_error();
printf("n");
if (oclose(&cda)) {
printf("Error closing cursor!n");
return -1;
}
if (ologof(&lda)) {
printf("Error logging off!n");
return -1;
}
exit(1);
}
oci_error()
{
text msg[600];
sword rv;
rv = oerhms(&lda, cda.rc, msg, 600);
printf("nn%.*s", rv, msg);
printf("Processing OCI function %sn", oci_func_tab[cda.fc]);
if (oclose(&cda))
printf("Error closing cursor!n");
if (ologof(&lda))
printf("Error logging off!n");
exit(1);
}
|
把olog改为
olog(&lda,hda,"scott/tiger@oraclesid_192.168.0.1",...)
既可.
olog(&lda,hda,"scott/tiger@oraclesid_192.168.0.1",...)
既可.
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。