⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 008.htm

📁 Delphi书籍--Delphi网上教程
💻 HTM
字号:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>-->DELPHI专题文档-数据库应用-->通过DELPHI实现JAVA调用ORACLE数据库数据</TITLE>
<META NAME="keywords" CONTENT=" DELPHI专题文档-数据库应用 通过DELPHI实现JAVA调用ORACLE数据库数据">
<META NAME="description" CONTENT=" - DELPHI专题文档-数据库应用 - 通过DELPHI实现JAVA调用ORACLE数据库数据">

</HEAD>
<a href="index8.html">返回</a>

<body text="#000000" aLink=#9900ff link=#006699 vLink=#006699 bgcolor="#FFFFFF" leftmargin="3" topmargin="3" marginheight="3" marginwidth="3">
<TABLE WIDTH="100%" CELLPADDING=10 CELLSPACING=0 BORDER=0>
<TR>

<TD class="tt2" bgcolor="#F5F8F8" width="84%"><center><B><FONT style="FONT-SIZE: 16.5pt" COLOR="#FF6666" FACE="楷体_GB2312">通过DELPHI实现JAVA调用ORACLE数据库数据</FONT></B></center>
<hr color="#EE9B73" size="1" width="94%">

<p><span style="font-size: 9pt"><font color="#ffffff">----</font> 在开发WWW网络浏览软件中,时常要用到JAVA画一些生产管理图形,而且大量的图形数据存于网络数据库ORACLE中,现在常用的方法是使用JDBC来实现对数据库的操作,但是,如果手头没有它驱动程序,则就无法对数据库进行操作。其实,我们可以使用DELPHI开发JAVA的ORACLE数据接口软件,就具体实现方法简述如下。 
</span></p> 
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> <b>一、系统设置:</b> 
</span></p> 
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> 1. 用SQL NET 设置ORACLE数据库所在服务器的IP地址别名,这里假设名字是oracle1; 
</span></p> 
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> 2. 建立ORACLE ODBC数据源; 
</span></p> 
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> 进入控制面板的ODBC数据源,然后点击Systen 
DSN,再点击Add按钮选择Microsoft ODBC Driver Oracle,在Data Source Name框中输入数据源名(test),在User 
Name框中输入ORACLE数据用户名(假设为user1)最后在Connect String框中输入在SQL 
NET中建立的ORACLE数据库别名oracle1; </span></p> 
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> 
建立好以上两步后,则DELPHI的BDE Administrator中自动生成一个test数据接口,如下图: 
</span></p> 
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> <b>二、用DELPHI开发读取ORACLE数据库数据的CGI 
程序</b> </span></p> 
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> 进入DELPHI编程环境,去掉FORM页及其它控件,然后输入以下程序。 
</span></p> 
<BR> 
<pre><span style="font-size: 9pt">
program testcgi;
{$apptype console}
uses
SysUtils, DBtables;
var
Table1: TTable;//用于读ORACLE数据库数据
Database1: TDatabase;//用于定义ORACLE别名及用户名和口令
i,ss,code:integer;
my,cc:string;
begin
writeln('CONTENT-TYPE: TEXT/HTML');//CGI程序要求的数据头信息
writeln;//保留一行空格
my:=paramstr(1);//读入JAVA传来的信息
Table1:=TTable.Create(nil);//创建Table控件
Database1:=TDatabase.Create(nil);//创建Database控件
try
Database1.aliasname:='test';//ORACLE别名
Database1.databasename:='test';
Database1.Params.Clear;
Database1.Params.add('USER NAME=user1');//用户名
Database1.Params.add('PASSWORD=userpassword');//口令
Database1.loginprompt:=false;
Database1.connected:=true;
Database1.open; //打开数据库通道
Table1.databasename:='test';
Table1.tablename:='cbkt';//ORACLE表名
table1.Active := True;
Table1.open;//打开ORACLE表
Table1.first;
//计算满足条件井数
i:=0;
while (not table1.eof) do
begin
if (Table1.FieldByName('ny').asstring=my) then
begin
write(Table1.FieldByName('jh').asstring+',');
val(Table1.Fields[2].asstring,ss,code);
if ss&gt;0 then
write(ss*100)
else
write('0.0');
write(',');
val(Table1.Fields[3].asstring,ss,code);
if ss &gt;0 then
write(ss*100)
else
write('0.0');
end;
table1.next
end;
finally
table1.close;
table1.free;
end;
end.
</span></pre> 
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> 
把以上程序编译后拷入服务器的CGI目录。 </span></p> 
<p><span style="font-size: 9pt"><font color="#ffffff">----</font> <b>三、JAVA部分程序</b> 
</span></p> 
<BR> 
<pre><span style="font-size: 9pt">


//test.java  编写:王兵  1999/11/30
import java.awt.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.applet.*;
public class test extends Applet {
。。。。。。。。
。。。。。。。
。。。。。。
//调用testcgi.exe实现读入ORACLE数据
public boolean action(Event evt,Object obj)
{ String s1=(String)obj;
if(s1==&quot;取数据&quot;)
return test_xx(&quot;http://10.65.76.64/scripts/testcgi.exe?&quot;+
year.getSelectedItem());
return true;
}
public boolean test_xx(String post)
{。。。。。。。。。。。
。。。。。。。。。。。
try{DataInputStream is;//数据输入流
URL url;//通过网传数据
url=new URL(post);
URLConnection connection=url.openConnection();//打开数据流
is=new DataInputStream(connection.getInputStream());
	 String inputline;
mcv.error=null;
	 if((inputline=is.readLine())==null)//无数据
	  {mcv.error=new String(&quot;无数据可读!!!&quot;);
	   status_field.setText(&quot;无数据可读!!!&quot;);
mcv.repaint();//画布刷新
	   return true;
	  }
	 status_field.setText(&quot;取x,y数据...&quot;);
if ((inputline=is.readLine())==null)
{mcv.error=new String(&quot;无数据可读!!!&quot;);
mcv.repaint();//画布刷新
	   return true;
	  }
mcv.bktx=new String[10];
mcv.bkty=new String[10];
mcv.bktjh=new String[10];


status_field.setText(&quot;取图形数据...&quot;);
js=1;//计井数
for (i=0;i&lt;10;i++)
{//每行3个字段
    inputline=&quot;is.readLine();&quot;
    if (inputline=&quot;=null)&quot;
    {
        break;
    }
    p1=&quot;inputline.indexOf(',');&quot;
    p2=&quot;inputline.lastIndexOf(',');&quot;
    mcv.bktjh[js]=&quot;inputline.substring(0,p1);&quot;
    mcv.bktx[js]=&quot;inputline.substring(p1+1,p2).trim();&quot;
    mcv.bkty[js]=&quot;inputline.substring(p2+1).trim();&quot;
    status_field.setText(&quot;bktx[&quot;+ String.valueOf(js)+&quot;]&quot;+mcv.bkty[js]);
    js=&quot;js+1;&quot;
    }
    is.close();
    status_field.setText(&quot;OK1&quot;);
    mcv.repaint();
}
catch(MalformedURLException me)
{
    System.err.println(&quot;MalformedURLException: &quot;+me);
}
catch(IOException ioe)
{
    System.err.println(&quot;IOException: &quot;+ioe);
}
catch(NumberFormatException e)
{
    if(mcv.error=&quot;=null)&quot; mcv.error=&quot;new&quot; String(&quot;数据格式出错B!!!&quot;+e);
    status_field.setText(mcv.error); mcv.repaint();
}
status_field.setText(&quot;数据读完!!!&quot;);
return true;
}
}
。。。。。。。。。。。。。 。。。。。。。。。。。。 </pre> 
<font 
color="#ffffff">----</font> 
<BR> 
<b>四、最后在自己的起始页HTML文件中加入如下程序段就行了。</b> 
</span> 
<hr color="#EE9B73" size="1" width="94%"> 
 
</TD> 
 
</TR> 
</table> 
</BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -