tailieunhanh - Database systems concepts 4th edition phần 3

EXEC SQL Đóng c END-EXEC SQLJ, nhúng Java của SQL, cung cấp một biến thể của Đề án trên, vòng lặp Java được sử dụng ở vị trí con trỏ. SQLJ liên kết các kết quả của một truy vấn với một iterator, và (tiếp theo phương pháp) của giao diện Iterator Java có thể được sử dụng để bước thông qua các bộ dữ liệu kết quả, cũng giống như các ví dụ trước đó sử dụng lấy con trỏ. | Silberschatz-Korth-Sudarshan Database System Concepts Fourth Edition II. Relational Databases 4. SQL The McGraw-Hill Companies 2001 Dynamic SQL 175 We must use the close statement to tell the database system to delete the temporary relation that held the result of the query. For our example this statement takes the form EXEC SQL close c END-EXEC SQLJ the Java embedding of SQL provides a variation of the above scheme where Java iterators are used in place of cursors. SQLJ associates the results of a query with an iterator and the next method of the Java iterator interface can be used to step through the result tuples just as the preceding examples use fetch on the cursor. Embedded SQL expressions for database modification update insert and delete do not return a result. Thus they are somewhat simpler to express. A databasemodification request takes the form EXEC SQL any valid update insert or delete END-EXEC Host-language variables preceded by a colon may appear in the SQL databasemodification expression. If an error condition arises in the execution of the statement a diagnostic is set in the SQLCA. Database relations can also be updated through cursors. For example if we want to add 100 to the balance attribute of every account where the branch name is Perryridge we could declare a cursor as follows. declare c cursor for select from account where branch-name Perryridge for update We then iterate through the tuples by performing fetch operations on the cursor as illustrated earlier and after fetching each tuple we execute the following code update account set balance balance 100 where current of c Embedded SQL allows a host-language program to access the database but it provides no assistance in presenting results to the user or in generating reports. Most commercial database products include tools to assist application programmers in creating user interfaces and formatted reports. We discuss such tools in Chapter 5 Section . Dynamic SQL The dynamic .