Chinaunix

标题: 在tuxedo里不能访问oracle表 [打印本页]

作者: xinxinhao    时间: 2007-11-21 13:31
标题: 在tuxedo里不能访问oracle表
我已经把oralce10和tuxedo9。1完全配置好料,,一切都好了,系统是suse linux 10.1 x86 32bit

oracle和tuxedo都能正常启动运行。。。但是在写测试的程序的时候,在server端 的程序里调用exec sql delete from tables where username=:db_code..

结果无法运行。。。清问高如何解决。。。

非常感谢!
客户程序如下:我oracle10只有一个数据库是orcl
oracleclient.c
#include <stdio.h>
#include <atmi.h>
#include <string.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
        char *sendbuf,*recvbuf;
        long sendlen,recvlen;
        int ret;
        if(argc!=2){
                printf("please call the format as : oracleclient %s \n",argv[0]);
                (void) fprintf(stderr, "Usage: oracleclient string\n");
                exit(1);
        }
        if(tpinit((TPINIT *)NULL)==-1){
                (void)fprintf(stderr,"failed to init!\n");
                exit(1);
        }
        sendlen=strlen(argv[1]);
        if((sendbuf=(char *)tpalloc("STRING",NULL,sendlen+1))==-1){
                (void)fprintf(stderr,"failed to allocate memory to sendbuf!\n");
                tpterm();
                exit(1);
        }
        if((recvbuf=(char *)tpalloc("STRING",NULL,5*sendlen+1))==-1){
                (void)fprintf(stderr,"failed to allocate memory for recvbuf!\n");
                tpterm();
                exit(1);
        }
        strcpy(sendbuf,argv[1]);
        ret = tpcall("ORACLES", (char *)sendbuf, 0, (char **)&recvbuf, &recvlen, (long)0);
        if(ret==-1){
                (void) fprintf(stderr, "Can't send request to service oracleserver\n");
                (void) fprintf(stderr, "Tperrno = %d, %s\n, ", tperrno, tpstrerror(tperrno));
                tpfree(sendbuf);
                tpfree(recvbuf);
                tpterm();
                exit(1);
        }
        (void)fprintf(stdout,"the return result is :%s \n",recvbuf);
        tpfree(sendbuf);
        tpfree(recvbuf);
        tpterm();
        return 0;
}


服务器server程序如下:
oracleserv.pc

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <atmi.h>
#include <userlog.h>
exec sql include sqlca;

tpsvrinit(int argc,char *argv[])
{
        if(tpopen()==-1){
                printf("error to connect to oracle!\n");
        }
        printf("the oracleserv successfully to connect to db2 in linux!\n");
        return 0;
}

ORACLES(TPSVCINFO *rqst)
{
        exec sql begin declare section;
                char db_string[50];
        exec sql end declare section;
        int i=0;
        for(i=0;i<rqst->len-1;i++){
                db_string=rqst->data;
        }
        exec sql delete from system.hmptest where username=:db_string;
        if(sqlca.sqlcode!=0){
                printf("delete error!\n");
                tpreturn(TPFAIL,0,NULL,0,0);
        }
        tpreturn(TPSUCCESS,0,rqst->data,0L,0);
}

tpsvrdone()
{
        if(tpclose()==-1){
                printf("oracleserv close error!\n");
                return;
        }
        printf("oracleserv disconnected!\n");
        return;
}

编译完全通过:
proc oracleserv.c parse=full include=/home/oracle/oracle/product/10.2.0/db_1/precomp/public include=/home/tuxedo/bea/tuxedo9.1/include

buildserver -o oracleserv -f "oracleserv.c -I/home/oracle/oracle/product/10.2.0/db_1/precomp/public" -r Oracle_XA -s ORACLES

没有错误。。正常运行
buildclient -o oracleclient -f oracleclient.c

但是那个exec sql delete from system.hmptest where username=:db_string;,..为什么不能执行
我的RM文件里用户密码是system/oracle

在sqlplus 里system/oracle能完全操作hmptest数据表。。。

哪位大侠能告诉我为什么。。。非常感谢!
作者: simhare    时间: 2009-06-22 20:58
标题: 回复 #1 xinxinhao 的帖子
哦,这个是2007年的帖子,不知道你当时问题解决了吗?怎么解决的?
作者: simhare    时间: 2009-06-22 21:02
标题: 回复 #1 xinxinhao 的帖子
但是那个exec sql delete from system.hmptest where username=:db_string;,..为什么不能执行
我的RM文件里用户密码是system/oracle
===========================
oracleserv.pc
这个是pro*c程序吗?怎么没有main()?
===========================
exec sql begin declare section;
                char db_string[50];
        exec sql end declare section;
这个不是应该在程序开头吗?
作者: simhare    时间: 2009-06-22 21:14
但是那个exec sql delete from system.hmptest where username=:db_string;,..为什么不能执行
=================
能说说怎么个不能执行法吗?
报什么错?还是没有响应?
作者: simhare    时间: 2009-06-22 21:18
我知道pro*c/c++,经过预编译后都是.cc了,可是我还是想知道Tuxedo的client端和server端可以用不同的语言写吗?
============
我看你前面是.c后面是.pc,这样可以吗?
作者: yulihua49    时间: 2009-06-26 22:28
原帖由 xinxinhao 于 2007-11-21 13:31 发表
我已经把oralce10和tuxedo9。1完全配置好料,,一切都好了,系统是suse linux 10.1 x86 32bit

oracle和tuxedo都能正常启动运行。。。但是在写测试的程序的时候,在server端 的程序里调用exec sql delete fro ...

在tpsvrinit()中打开数据库!
作者: simhare    时间: 2009-06-27 05:44
原帖由 yulihua49 于 2009-6-26 22:28 发表

在tpsvrinit()中打开数据库!

--------------------------------------
怎么"在tpsvrinit()中打开数据库!"?
我是这么做的:
tpsvrinit(int argc,char *argv[])
{

      EXEC SQL BEGIN DECLARE SECTION;
                char  *uid="pw/pw@wilson";
                float salary;
        EXEC SQL END DECLARE SECTION;   
        EXEC SQL CONNECT :uid;

        if(tpopen()==-1){
                printf("error to connect to oracle!\n");
        }
        printf("the oracleserv successfully to connect to db2 in linux!\n");
        return 0;
}
这样可以吗?

[ 本帖最后由 simhare 于 2009-6-27 05:46 编辑 ]
作者: simhare    时间: 2009-06-27 05:48
标题: 回复 #1 xinxinhao 的帖子
谁知道
=======
tpsvrinit(int argc,char *argv[])
{
        if(tpopen()==-1){
                printf("error to connect to oracle!\n");
        }
        printf("the oracleserv successfully to connect to db2 in linux!\n");
        return 0;
}
=======
这里需不需要打开数据库连接?怎么打开?
作者: simhare    时间: 2009-06-27 05:49
标题: 回复 #1 xinxinhao 的帖子
---------------
这个板块人好少啊!?
有没有早起的,早期做过Tuxedo的朋友们?
作者: simhare    时间: 2009-06-27 05:53
标题: 回复 #1 xinxinhao 的帖子
这一节,我想做的是返回一个字符串(有兄弟说C里面应该只有字符数组)给调用我的这里的ORACLE这个Service的程序,应该怎么做
==============
服务器server程序如下:
oracleserv.pc

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <atmi.h>
#include <userlog.h>
exec sql include sqlca;

tpsvrinit(int argc,char *argv[])
{
        if(tpopen()==-1){
                printf("error to connect to oracle!\n");
        }
        printf("the oracleserv successfully to connect to db2 in linux!\n");
        return 0;
}

ORACLES(TPSVCINFO *rqst)
{
        exec sql begin declare section;
                char db_string[50];
        exec sql end declare section;
        int i=0;
        for(i=0;i<rqst->len-1;i++){
                db_string=rqst->data;
        }
        exec sql delete from system.hmptest where username=:db_string;
        if(sqlca.sqlcode!=0){
                printf("delete error!\n");
                tpreturn(TPFAIL,0,NULL,0,0);
        }
        tpreturn(TPSUCCESS,0,rqst->data,0L,0);
}

tpsvrdone()
{
        if(tpclose()==-1){
                printf("oracleserv close error!\n");
                return;
        }
        printf("oracleserv disconnected!\n");
        return;
}

==============
作者: simhare    时间: 2009-06-27 05:55
标题: 回复 #1 xinxinhao 的帖子
我还想问下,需要tpsvrdone()吗?这个不是Tuxedo自己管理,默认添加的吗?:
==========
服务器server程序如下:
oracleserv.pc

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <atmi.h>
#include <userlog.h>
exec sql include sqlca;

tpsvrinit(int argc,char *argv[])
{
        if(tpopen()==-1){
                printf("error to connect to oracle!\n");
        }
        printf("the oracleserv successfully to connect to db2 in linux!\n");
        return 0;
}

ORACLES(TPSVCINFO *rqst)
{
        exec sql begin declare section;
                char db_string[50];
        exec sql end declare section;
        int i=0;
        for(i=0;i<rqst->len-1;i++){
                db_string=rqst->data;
        }
        exec sql delete from system.hmptest where username=:db_string;
        if(sqlca.sqlcode!=0){
                printf("delete error!\n");
                tpreturn(TPFAIL,0,NULL,0,0);
        }
        tpreturn(TPSUCCESS,0,rqst->data,0L,0);
}

tpsvrdone()
{
        if(tpclose()==-1){
                printf("oracleserv close error!\n");
                return;
        }
        printf("oracleserv disconnected!\n");
        return;
}

作者: simhare    时间: 2009-06-27 05:57
标题: 回复 #1 xinxinhao 的帖子
各位高手们先在这里给个简单的方向性的说法呀?!
作者: yulihua49    时间: 2009-06-28 11:32
[quote]原帖由 simhare 于 2009-6-27 05:44 发表

--------------------------------------
怎么"在tpsvrinit()中打开数据库!"?
EXEC SQL BEGIN DECLARE SECTION;
                char  *uid="pw/pw@wilson";
                float salary;
        EXEC SQL END DECLARE SECTION;   
        EXEC SQL CONNECT :uid;
        if(tpopen()==-1){ //改成 SQL_CODE?proc的错误状态,有点忘了。
                userlog("error to connect to oracle!\n");
                return -1;
        }
作者: yulihua49    时间: 2009-07-06 17:06
原帖由 simhare 于 2009-6-27 05:57 发表
各位高手们先在这里给个简单的方向性的说法呀?!

在tuxedo服务器里最好使用OCI,我们用了一个开源接口sqlora8.
你在客户端发送一个SQL语句,到服务器后prepare这个语句,执行,并把结果以字符串形式返回。

我们搞了一个更复杂的工具(用起来很简单),帮助你生成SQL语句,执行,并以JSON格式返回结果集。
http://www.itpub.net/viewthread. ... p;extra=&page=1

[ 本帖最后由 yulihua49 于 2009-7-6 17:09 编辑 ]




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2