java學習心得筆記
把oracle8.1.6/lib/jdbc/*.zip copy 到 %java_home%/jre/lib/ext/*.jar
如果光copy不ren為.jar是沒有用的。
4. 事務處理
本地事務
java.sql.connection接口可以控制事務邊界(即開始和結束)。
在事務開始的時候調用setautocommit( false ), 而在中止事務時調用rollback或commit()方法。這類事務叫本地事務。
分布式事務
但是,在特定的情況下,可能有多個客戶(例如兩個不同的servlet或ejb組件)參與了同一個事務。
或者,客戶在同一個事務中可能會執行跨越多個數據庫的數據庫操作。
jdbc2.0 optional package 同jta一起來實現分布式樣事務。
5. 一些技巧
檢索自動產生的關鍵字
為了解決對獲取自動產生的或自動增加的關鍵字的值的需求,jdbc 3.0 api 現在將獲取這種值變得很輕松。要確定任何所產生的關鍵字的值,只要簡單地在語句的 execute() 方法中指定一個可選的標記,表示您有興趣獲取產生的值。您感興趣的程度可以是 statement.return_generated_keys,也可以是 statement.no_generated_keys。在執行這條語句后,所產生的關鍵字的值就會通過從 statement 的實例方法 getgeneratedkeys() 來檢索 resultset 而獲得。resultset 包含了每個所產生的關鍵字的列。清單 1 中的示例創建一個新的作者并返回對應的自動產生的關鍵字。
清單 1. 檢索自動產生的關鍵字
statement stmt = conn.createstatement();
// obtain the generated key that results from the query.
stmt.executeupdate("insert into authors " +
'(first_name, last_name) " +
"values ('george', 'orwell')",
statement.return_generated_keys);
resultset rs = stmt.getgeneratedkeys();
if ( rs.next() ) {
// retrieve the auto generated key(s).
int key = rs.getint();
}
jta/jts
1.jta/jts基本知識
服務器實現jts是否對應用程序開發人員來說不是很重要的。
對你來說,應該把jta看作是可用的api。
jta是用來開發distributed tansaction的 api.
而jts定義了支持jta中實現transaction manager 的規范。
javatransaction service (jts) specifies the implementation of a transaction manager which supports the java transaction api (jta) 1.0 specification at the high-level and implements the java mapping of the omg object transaction service (ots) 1.1 specification at the low-level. jts uses the standard corba orb/ts interfaces and internet inter-orb protocol (iiop) for transaction context propagation between jts transaction managers.
a jts transaction manager provides transaction services to the parties involved in distributed transactions: the application server, the resource manager, the standalone transactional application, and the communication resource manager (crm).
2.jta
1.1 事務處理的概念
jta實際上是由兩部分組成的:一個高級的事務性客戶接口和一個低級的 x/open xa接口。
我們關心的是高級客戶接口,因為bean可以訪問它,而且是推薦的客戶應用程序的事務性接口。
低級的xa接口是由ejb服務器和容器使用來自動協調事務和資源(如數據庫)的
1.1.1事務劃分
a.程序劃分
使用usertransaction啟動jta事務
the usertransaction interface defines the methods that allow an application to explicitly manage transaction boundaries.(from j2ee api document)