浏览应用方案 假设需要构建一个应用,该应用支持一家公司的市场营销分部,该分部维护面向金融的 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"(在参考资料中)。