瀏覽應用方案 假設需要構建一個應用,該應用支持一家公司的市場營銷分部,該分部維護面向金融的 Web 站點。該站點答應人們注冊為客戶,跟蹤他們的投資總額,以及在電子公告板上發表意見。另外還假設,支持該站點的數據存儲在 DB2 的表中。以下代碼樣本顯示如何創建這些表。
在 DB2 中創建樣本表的 SQL 語句
create table client ( id int not null primary key, name varchar(30), email varchar(30), phone varchar(12), regdate date, mktg char, constraint check1 check (mktg in (′y′, ′Y′, ′n′, ′N′)) )
create table portfolio ( id int not null, clientID int not null references client, ticker varchar(10) not null, cost decimal (9,2), qty int, date date, primary key (id, clientID, ticker) )
create table boards ( msgno varchar(15) not null primary key, subject varchar(40), date date, clientID int not null references client )
select name, e-mail from client where id = ? select id, ticker, cost, qty, date from portfolio where clientid = ? select msgno, subject, date from boards where clientid = ?
測試時,在 VisualAge for Java WebSphere 測試環境中運行使用 DataSource 的 EJB 組件會很方便。有關如何在產品發行版 3.0.2 中這樣做的指示,請參閱 David Zimmerman 所著的 "Creating DataSources in the VisualAge for Java WebSphere Test Environment"(在參考資料中)。