所需軟件
如果您要跟隨我們逐步完成本文中給出的示例,那么您需要安裝以下軟件:
windows nt 4.0、windows 2000、windows xp professional 或 windows server 2003
能夠訪問一個已安裝的 oracle 數(shù)據(jù)庫(oracle8i 版本 3 8.1.7 或更高版本)
oracle 客戶機(版本 10.1.0.2.0 或更高版本)
oracle net(版本 10.1.0.2.0 或更高版本)
oracle data providers for .net(版本 10.1.0.2.0 或更高版本)
microsoft .net framework(版本 1.0 或更高版本)
microsoft .net 框架 sdk(版本 1.0 或更高版本)
如果您打算使用企業(yè)服務事務或分布式事務來開發(fā)和運行應用程序,那么您還需要安裝 oracle services for microsoft transaction server(10.1.0.2.0 或更高版本)。
您需要分別下載和安裝 .net 框架以及 sdk(先安裝框架)。您還需要下載和安裝 oracle 數(shù)據(jù)庫 10g,它包括 oracle data provider for .net (odp.net)。您可以選擇在不同計算機或同一計算機上安裝 odp.net 和數(shù)據(jù)庫服務器。
注意:odp.net 驅(qū)動程序針對 oracle 數(shù)據(jù)庫訪問進行了優(yōu)化,因此可以獲得最佳性能,并且它們還支持 oracle 數(shù)據(jù)庫的豐富特性,如 bfile、blob、clob、xmltype 等。如果您正在開發(fā)基于 oracle 數(shù)據(jù)庫的 .net 應用程序,那么就特性和性能來講,odp.net 無疑是最佳的選擇。
數(shù)據(jù)庫模式設置
首先,您需要設置數(shù)據(jù)庫模式,在此我們使用一個簡化的 web 商店示例。您必須首先創(chuàng)建一個名為 store 的用戶并按以下方式將所需的權限授予該用戶(您必須首先以擁有 create user 權限的用戶身份登錄數(shù)據(jù)庫才能創(chuàng)建用戶):
create user store identified by store;
grant connect, resource to store;
注意:您會在源代碼文件 db1.sql 中找到前兩個語句和該部分中出現(xiàn)的設置 store 模式的其他語句。
接下的語句以 store 用戶身份進行連接:
connect store/store;
以下語句創(chuàng)建了所需的兩個數(shù)據(jù)庫表,名稱分別為 product_types 和 products:
create table product_types (
product_type_id integer
constraint product_types_pk primary key,
name varchar2(10) not null
);
create table products (
product_id integer
constraint products_pk primary key,
product_type_id integer
constraint products_fk_product_types
references product_types(product_type_id),
name varchar2(30) not null,
description varchar2(50),
price number(5, 2)
);
注意:如果您在一個不同的模式中為 store 用戶創(chuàng)建了這些數(shù)據(jù)庫表,那么您將需要修改示例配置文件(您稍后將看到)中的模式名稱。
表 product_types 用于存儲示例在線商店可能庫存的產(chǎn)品類型的名稱,表 products 包含了所銷售產(chǎn)品的詳細信息。
下面的 insert 語句為表 product_types 和 products 添加行:
insert into product_types (
product_type_id, name
) values (
1, 'book'
);
insert into product_types (
product_type_id, name
) values (
2, 'dvd'
);
insert into products (
product_id, product_type_id, name, description, price
) values (
1, 1, 'modern science', 'a description of modern science', 19.95
);
insert into products (
product_id, product_type_id, name, description, price
) values (
2, 1, 'chemistry', 'introduction to chemistry', 30.00
);
insert into products (
product_id, product_type_id, name, description, price
) values (
3, 2, 'supernova', 'a star explodes', 25.99
);
insert into products (
product_id, product_type_id, name, description, price
) values (
4, 2, 'tank war', 'action movie about a future war', 13.95
);
commit;
接下來,您將了解有關數(shù)據(jù)庫事務的內(nèi)容。
新聞熱點
疑難解答
圖片精選