我是新手,问大家这个简单的问题。我试过一次,但是总是用c的时候在链接oracle提供的库时候出问题,而c++的时候则编译时会报错。我怀疑是包含库时有问题,但是我已在工程设置中包含了它的库。是不是函数调用时有问题?请各位指教,详细描述最好。底线50分!

解决方案 »

  1.   

    *  An example program which adds new employee
     *  records to the personnel data base.  Checking
     *  is done to insure the integrity of the data base.
     *  The employee numbers are automatically selected using
     *  the current maximum employee number as the start.
     *
     *  The program queries the user for data as follows:
     *
     *  Enter employee name:
     *  Enter employee job:
     *  Enter employee salary:
     *  Enter employee dept:
     *
     *  The program terminates if return key (CR) is entered
     *  when the employee name is requested.
     *
     *  If the record is successfully inserted, the following
     *  is printed:
     *
     *  "ename" added to department "dname" as employee # "empno"
     *
     *  The size of the HDA is defined by the HDA_SIZE constant,
     *  which is declared in ocidem.h to be 256 bytes for 32-
     *  bit architectures and 512 bytes for 64-bit architectures.
     */#include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string.h>
    #include <oratypes.h>
    /* LDA and CDA struct declarations */
    #include <ocidfn.h>
    #ifdef __STDC__
    #include <ociapr.h>
    #else
    #include <ocikpr.h>
    #endif
    /* demo constants and structs */
    #include <ocidem.h>/* oparse flags */
    #define  DEFER_PARSE        1
    #define  NATIVE             1
    #define  VERSION_7          2
    text *username = (text *) "SCOTT";
    text *password = (text *) "TIGER";/* Define SQL statements to be used in program. */
    text *insert = (text *) "INSERT INTO emp(empno, ename, job, sal, deptno)\
        VALUES (:empno, :ename, :job, :sal, :deptno)";
    text *seldept = (text *) "SELECT dname FROM dept WHERE deptno = :1";
    text *maxemp = (text *) "SELECT NVL(MAX(empno), 0) FROM emp";
    text *selemp = (text *) "SELECT ename, job FROM emp";/* Define an LDA, a HDA,  and two cursors. */
    Lda_Def lda;
    ub4     hda[HDA_SIZE/sizeof(ub4)];
    Cda_Def cda1;
    Cda_Def cda2;
    void err_report();
    void do_exit();
    void myfflush();main()
    {
        sword empno, sal, deptno;
        sword len, len2, rv, dsize, dsize2;
        sb4   enamelen, joblen, deptlen;
        sb2   sal_ind, job_ind;
        sb2   db_type, db2_type;
        sb1   name_buf[20], name2_buf[20];
        text  *cp, *ename, *job, *dept;/*
     *  Connect to ORACLE and open two cursors.
     *  Exit on any error.
     */
        if (olog(&lda, (ub1 *)hda, username, -1, password, -1,
                 (text *) 0, -1, (ub4)OCI_LM_DEF))
        {
            err_report(&lda);
            exit(EXIT_FAILURE);
        }
        printf("Connected to ORACLE as %s\n", username);    if (oopen(&cda1, &lda, (text *) 0, -1, -1, (text *) 0, -1))
        {
            err_report(&cda1);
            do_exit(EXIT_FAILURE);
        }
        if (oopen(&cda2, &lda, (text *) 0, -1, -1, (text *) 0, -1))
        {
            err_report(&cda2);
            do_exit(EXIT_FAILURE);
        }    /* Turn off auto-commit. Default is off, however. */
        if (ocof(&lda))
        {
            err_report(&lda);
            do_exit(EXIT_FAILURE);
        }....................................................
      

  2.   

    谢谢回复!
    好像oracle提供了一些例子,和你贴的类似。
    我就是用的例子。,cdemo1.c
    da但是编译通过,连接时找不到函数入口,但我已经包含了那个库,为社么不行呢?是不是还要设置什么?
    谢谢!
      

  3.   

    11.obj : error LNK2001: unresolved external symbol _ocof
    111.obj : error LNK2001: unresolved external symbol _do_exit
    111.obj : error LNK2001: unresolved external symbol _oopen
    111.obj : error LNK2001: unresolved external symbol _err_report
    111.obj : error LNK2001: unresolved external symbol _olog
    你写的程序我编译通过,链接出错,如上。
    你是怎么包含oracle的库的?能告诉我吗?
    肯定给分!
      

  4.   

    include oci\include
     
    加oci.lib入你的工程另外使用8以上的oci版