Java 與Delphi 的整合 |
答題得分者是:jackkcg
|
ddy
站務副站長 發表:262 回覆:2105 積分:1169 註冊:2002-07-13 發送簡訊給我 |
|
jackkcg
站務副站長 發表:891 回覆:1050 積分:848 註冊:2002-03-23 發送簡訊給我 |
http://www.javadelphi.com/
http://www.madrigal.com.au/papers/java4delphi/j4d5.htm
http://www.hallogram.com/delphi2java/database.html
http://www.webtechcorp.com/delphi-training-courses/delphi-hands-on-training-courses.htm
*********************************************************************
http://www2.ccw.com.cn/tips/2k01/011205_05.asp
http://www2.ccw.com.cn/tips/2k01/011205_05.asp
通過DELPHI實現JAVA調用ORACLE資料庫資料
大慶採油六廠採油工藝研究所
王兵
---- 在開發WWW網路瀏覽軟體中,時常要用到JAVA畫一些生?管理圖形,而且大量的圖形資料存於網路資料庫ORACLE中,現在常用的方法是使用JDBC來實現對資料庫的操作,但是,如果手頭沒有它驅動程式,則就無法對資料庫進行操作。其實,我們可以使用DELPHI開發JAVA的ORACLE資料介面軟體,就具體實現方法簡述如下。 ---- 一、系統設置: ---- 1. 用SQL NET 設置ORACLE資料庫所在伺服器的IP地址別名,這裏假設名字是oracle1; ---- 2. 建立ORACLE ODBC資料源; ---- 進入控制面板的ODBC資料源,然後點擊Systen DSN,再點擊Add按鈕選擇Microsoft ODBC Driver Oracle,在Data Source Name框中輸入資料源名(test),在User Name框中輸入ORACLE資料用戶名(假設?user1)最後在Connect String框中輸入在SQL NET中建立的ORACLE資料庫別名oracle1; ---- 建立好以上兩步後,則DELPHI的BDE Administrator中自動生成一個test資料介面,如下圖: ---- 二、用DELPHI開發讀取ORACLE資料庫資料的CGI 程式 ---- 進入DELPHI編程環境,去掉FORM頁及其它控制項,然後輸入以下程式。 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>0 then
write(ss*100)
else
write('0.0');
write(',');
val(Table1.Fields[3].asstring,ss,code);
if ss >0 then
write(ss*100)
else
write('0.0');
end;
table1.next
end;
finally
table1.close;
table1.free;
end;
end. ---- 把以上程式編譯後拷入伺服器的CGI目錄。
---- 三、JAVA部分程式 //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=="取資料")
return test_xx("http://10.65.76.64/scripts/testcgi.exe?"
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("無數據可讀!!!");
status_field.setText("無數據可讀!!!");
mcv.repaint();//畫布刷新
return true;
}
status_field.setText("取x,y資料...");
if ((inputline=is.readLine())==null)
{mcv.error=new String("無數據可讀!!!");
mcv.repaint();//畫布刷新
return true;
}
mcv.bktx=new String[10];
mcv.bkty=new String[10];
mcv.bktjh=new String[10]; status_field.setText("取圖形資料...");
js=1;//計井數
for (i=0;i< 10;i )
{//每行3個欄位
inputline=is.readLine();
if (inputline==null) {break;}
p1=inputline.indexOf(',');
p2=inputline.lastIndexOf(',');
mcv.bktjh[js]=inputline.substring(0,p1);
mcv.bktx[js]=inputline.substring(p1 1,p2).trim();
mcv.bkty[js]=inputline.substring(p2 1).trim();
status_field.setText("bktx["
String.valueOf(js) "]" mcv.bkty[js]);
js=js 1;
} is.close();
status_field.setText("OK1");
mcv.repaint();
}catch(MalformedURLException me)
{System.err.println("MalformedURLException: " me);}
catch(IOException ioe){
System.err.println("IOException: " ioe);
}catch(NumberFormatException e)
{if(mcv.error==null)
mcv.error=new String("資料格式出錯B!!!" e);
status_field.setText(mcv.error);
mcv.repaint();
}
status_field.setText("資料讀完!!!");
return true;
}
}
。。。。。。。。。。。。。
。。。。。。。。。。。。 ---- 四、最後在自己的起始頁HTML文件中加入如下程式段就行了。 < !test.html 1999/11/30 >
< HTML >
< HEAD >
。。。。。。
。。。。。。
< BODY >
。。。。。。
< APPLET CODE="test.class" WIDTH=200 HEIGHT=40 >< /APPLET >
。。。。。。
< /BODY >
。。。。。。
。。。。。。
< /HTML > ---- 以上程式在IBM 330 Server上調試通過,開發環境Visual J 6.0。 發表人 - jackkcg 於 2002/10/15 22:48:03
------
********************************************************** 哈哈&兵燹 最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好 Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知 K.表Knowlege 知識,就是本站的標語:Open our mind |
ddy
站務副站長 發表:262 回覆:2105 積分:1169 註冊:2002-07-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |