作業一 using dbms ( 使用 db2) c. j. date 課本習題 4.1~4.6 ex. 4.5, 4.6...
TRANSCRIPT
![Page 1: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/1.jpg)
作業一 Using DBMS ( 使用 DB2)
C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100)
Using the suppliers-parts-projects database, write a program with embedded SQL statements to list all supplier rows, in supplier number order. Each supplier row should be immediately followed in the listing by all project rows for projects supplied by that supplier, in project number order.
create database selection update query catalog . . . embedded SQL (program)
![Page 2: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/2.jpg)
![Page 3: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/3.jpg)
![Page 4: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/4.jpg)
![Page 5: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/5.jpg)
DB2 安裝使用
先安裝 J2SDK J2sdk-1_4_2.exe 再安裝 DB2 Universal Database Personal
Edition 下戴處 IBM web side
課程網頁上為 windows 版本 RELEASED PRODUCT: DB2 Universal Database (DB2 Personal Edition for Wi
ndows (32 Bit))
FREE download of DB2 Universal Database products.
![Page 6: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/6.jpg)
DB2 控制中心
![Page 7: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/7.jpg)
![Page 8: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/8.jpg)
![Page 9: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/9.jpg)
![Page 10: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/10.jpg)
![Page 11: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/11.jpg)
列出結果
![Page 12: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/12.jpg)
Java 連結 DB2 範例
java language & DB2
java
int a, b;a = 5;b =10*a;….EXEC SQL …..…..
SQL:
![Page 13: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/13.jpg)
設定 DB2 連結資訊環境
![Page 14: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/14.jpg)
設定 DB2 連結資訊環境
![Page 15: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/15.jpg)
Java 環境設定
我的電腦 ( 按右鍵 )-> 內容 :
C:\j2sdk1.4.2_01\lib\tools.jar
![Page 16: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/16.jpg)
Java 環境設定
;C:\j2sdk1.4.2_01\bin;
![Page 17: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/17.jpg)
使用 Javac 編譯程式
C:\work\dbtest.java : 使用者編輯的程式碼
![Page 18: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/18.jpg)
Embedded SQL Example
import java.sql.*; import java.lang.*; class dbtest { public static void main(String[] argv) throws Exception { int sum=0; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection ("jdbc:odbc:TEST"); Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); System.out.println(" 連上了~ "); String strSQL="SELECT * FROM DB147.S as S where CITY='london'"; System.out.println(strSQL); ResultSet rs=stmt.executeQuery(strSQL); sum=Integer.parseInt(argv[0]); if(sum>10){ System.out.print("sum > 10; "+"sum*0.5="+sum*0.5+"\n"); } else { System.out.print("sum <= 10; "+"sum+100="+(sum+100)+"\n"); } while(rs.next()){ sum=sum+rs.getInt("STATUS"); System.out.print(" "+rs.getString(1)+" "+rs.getInt("STATUS") + "\n"); } System.out.print("total status = $ "+sum + "\n"); } }
rs.next()
Next()
CITY='london’
![Page 19: 作業一 Using DBMS ( 使用 DB2) C. J. Date 課本習題 4.1~4.6 Ex. 4.5, 4.6 程式作業要使用 Embedded SQL 連結 DB2. EX. 4.1-4.6 (p.99-100) Using the suppliers-parts-projects](https://reader035.vdocument.in/reader035/viewer/2022081506/56649f455503460f94c66825/html5/thumbnails/19.jpg)
java 語言範例 結果