如何用Jsp(Java) 通过 BEA tuxedo 中间件 连接 oracle数据库???

janisttcb 2002-04-04 05:39:49
如何用Jsp(Java) 通过 BEA tuxedo 中间件 连接 oracle数据库???

并对数据库进行操作??请给个实例,谢谢!!
...全文
87 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinfanzi 2002-04-06
  • 打赏
  • 举报
回复
另外连接数据库,我是通过pc来完成的,因为我是将pc编译成tuxedo应用服务的,pc源代码如下:
#include <atmi.h>
#include <stdio.h>
#include <stdlib.h>
#include <fml32.h>
#include "webdatafld.h"
#include <string.h>

EXEC SQL INCLUDE sqlca.h;

int ora_connect(char conn_str[60])
{
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR connstr[60];
EXEC SQL END DECLARE SECTION;

connstr.len = (unsigned short)strlen(strcpy((char *)connstr.arr, conn_str));

EXEC SQL CONNECT :connstr;

if (sqlca.sqlcode < 0)
{
return 0;
}
else
{
return 1;
}
}

int tpsvrinit(int argc , char **argv)
{
if (tpopen() == -1)
{
argc = argc;
(void)userlog("insert: tpopen failed tperrno %d",tperrno);
return(-1);
}
userlog("tpopen success");
if(ora_connect("user114/user114@sz1000"))
{
userlog("connect success");
return 1;
}
else
{
userlog("connect failure");
return 0;
}
}

void tpsvrdone()
{
userlog("done");
tpclose();
}

void
#if defined(__STDC__) || defined(__cplusplus)
WEB114(TPSVCINFO *transb)
#else
WEB114(transb)
TPSVCINFO *transb;
#endif
{
typedef char vc2_arr[100];
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL TYPE vc2_arr IS VARCHAR2(100) REFERENCE;
int in_type[10];
vc2_arr in_value[10];
vc2_arr input_value[10];
int in_length[10];
int in_array_size;
int out_array_size;
int out_type[2000];
int out_length[2000];
vc2_arr out_value[2000];
vc2_arr out_lab_name[2000];
vc2_arr out_hzsm[2000];
EXEC SQL END DECLARE SECTION;

int i_count;
int flag;
int i;
FBFR32 *ibuf = (FBFR32*)transb->data;
FBFR32 *sendbuf;
FLDID32 field_id;

sendbuf = (FBFR32*)tpalloc("FML32",NULL,1024*1024);
Fget32(ibuf, REQTYPE,0,(char *)in_value[0], NULL);
Fget32(ibuf, CODE,0,(char *)in_value[1], NULL);
userlog("REQTYPE is : %s\n",in_value[0]);
userlog("CODE is : %s\n",in_value[1]);
in_length[0]=strlen(in_value[0]);
in_length[1]=strlen(in_value[1]);

EXEC SQL EXECUTE
BEGIN
pak_web.pro_web_114(
:in_type,
:in_value,
:in_length,
:in_array_size,
:out_array_size,
:out_type,
:out_value ,
:out_lab_name ,
:out_hzsm );
END;
END-EXEC;

if(sqlca.sqlcode < 0)
{
userlog("sql error =%d,%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
}

/*出参数解析*/
/*
userlog("exec procedure out value0 is...%s\n",out_value[0]);
userlog("exec procedure out value1 is...%s\n",out_value[1]);
userlog("exec procedure out value2 is...%s\n",out_value[2]);
userlog("exec procedure out value3 is...%s\n",out_value[3]);
userlog("exec procedure out name3 is...%s\n",out_lab_name[3]);
userlog("exec procedure out value4 is...%s\n",out_value[4]);
userlog("exec procedure out name4 is...%s\n",out_lab_name[4]);
userlog("exec procedure out value5 is...%s\n",out_value[5]);
userlog("exec procedure out name5 is...%s\n",out_lab_name[5]);
userlog("exec procedure out value6 is...%s\n",out_value[6]);
userlog("exec procedure out name6 is...%s\n",out_lab_name[6]);
userlog("exec procedure out value7 is...%s\n",out_value[7]);
userlog("exec procedure out name7 is...%s\n",out_lab_name[7]);
userlog("exec procedure out value8 is...%s\n",out_value[8]);
userlog("exec procedure out name8 is...%s\n",out_lab_name[8]);
userlog("exec procedure out value9 is...%s\n",out_value[9]);
userlog("exec procedure out hzsm is...%s\n",out_hzsm[0]);
*/

i_count = atoi(out_value[2]);

flag = atoi(out_value[0]);
if (flag == 0) /*成功*/
{
for (i=3;i<i_count;i++)
{
field_id = Fldid32(out_lab_name[i]);
Fchg32(sendbuf,field_id,-1,(char*)out_value[i],0);
}
}
else
{
userlog("exec procedure...error");
}
tpreturn(TPSUCCESS, 0, sendbuf, 0, 0);
}

void sql_msg(char *msg)
{
userlog("%s\n",msg);
userlog("sql error =%d,%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
}
jinfanzi 2002-04-06
  • 打赏
  • 举报
回复
以下是一个servlet程序,是用来连接tuxedo服务的:
package ServletWeb;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.NamingException;

//Package for Jolt
import bea.jolt.JoltException;
import bea.jolt.pool.*;
import bea.jolt.pool.servlet.*;
import weblogic.jndi.Environment;


/****************************************************************************
* Title: Servlet for 114 *
* Description: 这是一个用于114网上受理与Tuxedo Service 交互的Jolt Servlet *
* Copyright: Copyright (c) 2001 *
* Company: Wellhope *
* @author wangld *
* @version 1.0 *
****************************************************************************/

public class webService114 extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=gb2312";
/**Initialize global variables*/
private ServletSessionPoolManager b_mgr;
RequestDispatcher rd;

public void destroy()
{
b_mgr = null;
}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PerformTask(request,response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PerformTask(request,response);
}
public void init(ServletConfig config) throws ServletException
{
super.init(config);
/*Add your code here */
//初始化ServletSessionPoolManager的环境变量.
try
{
Environment environment = new Environment();
//Gets an initial context:得到一个初始的上下文关系.
Context context = environment.getInitialContext();
b_mgr = (ServletSessionPoolManager)context.lookup("bea.jolt.pool.SessionPoolManager");
return;
}
catch(NamingException namingexception)
{
throw new ServletException(namingexception.toString());
}
}

public void PerformTask(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType(CONTENT_TYPE);
ServletSessionPool servletsessionpool = (ServletSessionPool) b_mgr.getSessionPool("webjoltpool");
if (servletsessionpool == null)
{
System.out.println("Fail to look up session pool !");
return;
}
//调用Tuxedo服务:
//如果有入参请在这里对参数赋值:
String as[] = req.getParameterValues("SVCNAME");
String svrname = (String) as[0];
System.out.println(svrname);
ServletResult servletresult;
try
{
/*call 方法调用说明:
call(String, HttpServletRequest). Method in class bea.jolt.pool.servlet.ServletSessionPool
Invokes a BEA TUXEDO service without an explicit transaction.
call(String, HttpServletRequest, Transaction). Method in class bea.jolt.pool.servlet.ServletSessionPool
Invokes a BEA TUXEDO service.
参数说明: Input parameters for the BEA TUXEDO service are passed to this method
as a javax.servlet.http.HttpServletRequest object request.
The names of the members in request must match the names of
the BEA TUXEDO service parameters.
For input parameters, member names are the names of the HTML form field.
Any members with names that do not match the BEA TUXEDO service parameter names
are ignored. If no trancation is null.
*/
servletresult = servletsessionpool.call(as[0], req, null);
}
catch (SessionPoolException sessionpoolexception)
{
System.out.println("Your request cannot be completed at this moment.\n Diagnostic Message is: " + sessionpoolexception.getMessage());
return;
}
catch (ServiceException serviceexception)
{
System.out.println("Service exception,Error message:" + serviceexception.getMessage());
return;
}
catch (ApplicationException applicationexception)
{
ServletResult servletresult1 = (ServletResult) applicationexception.getResult();
System.out.println("Application error \n Application code is " + servletresult1.getApplicationCode());
return;
}
catch (Exception exception)
{
System.out.println("Unexpected exception Exception is " + exception);
return;
}
if (svrname.equalsIgnoreCase("WEB114"))
{
/***************查询业务类型**********************
* ---011 网上单位中文名称查询 *
* ---012 网上单位英文名称查询 *
* ---113 网址类别查询 *
************************************************/
System.out.println("reqtype is "+req.getParameter("REQTYPE"));
char querytype = req.getParameter("REQTYPE").charAt(0);
System.out.println("querytype: "+querytype);
String jspName="";
Vector vc = new Vector();
int i=0;
int count=0; /* 返回记录的条数 */
switch (querytype)
{
case '0' : /*网上关键字查询*/
{
count = servletresult.getCount("CODE");
System.out.println("servlet 0: "+count);
for (i=0;i<count;i++)
{
Vector vcin = new Vector();
vcin.removeAllElements();
vcin.addElement((String) servletresult.getStringValue("NAME", i, ""));
vcin.addElement((String) servletresult.getStringValue("CODE", i, ""));
vcin.addElement((String) servletresult.getStringValue("ADDR", i, ""));
vcin.addElement((String) servletresult.getStringValue("ADDR_CODE", i, ""));
vcin.addElement((String) servletresult.getStringValue("TEL", i, ""));
vcin.addElement((String) servletresult.getStringValue("ENGLISH_NAME", i, ""));
vcin.addElement((String) servletresult.getStringValue("ENGLISH_CODE", i, ""));
vc.addElement(vcin);
}
jspName="/wellhopeweb/web/114/webKey.jsp";
break;
}
case '1' : /*网上分类查询*/
{
count = servletresult.getCount("ID");
System.out.println("servlet 1: "+count);
for (i=0;i<count;i++)
{
Vector vcin = new Vector();
vcin.removeAllElements();
vcin.addElement((String) servletresult.getStringValue("ID", i, ""));
vcin.addElement((String) servletresult.getStringValue("NO", i, ""));
vcin.addElement((String) servletresult.getStringValue("NAME", i, ""));
vcin.addElement((String) servletresult.getStringValue("PROPERTY", i, ""));
vc.addElement(vcin);
}
jspName="/wellhopeweb/web/114/webClass.jsp";
break;
}
default :
{
System.out.println("No this query type!");
}
}
req.setAttribute("RESULTSET", (Vector) vc);
rd = getServletContext().getRequestDispatcher(jspName);
rd.forward(req, res);
}
}
}

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧