Download presentation
Presentation is loading. Please wait.
Published byBrittany Evans Modified over 9 years ago
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 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)
5
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 Windows (32 Bit)) FREE download of DB2 Universal Database products. RELEASED PRODUCT: DB2 Universal Database (DB2 Personal Edition for Windows (32 Bit))
6
DB2 控制中心
11
列出結果
12
Java 連結 DB2 範例 java language & DB2 java int a, b; a = 5; b =10*a; …. EXEC SQL ….. SQL:
13
設定 DB2 連結資訊環境
15
Java 環境設定 我的電腦 ( 按右鍵 )-> 內容 : C:\j2sdk1.4.2_01\lib\tools.jar
16
Java 環境設定 ;C:\j2sdk1.4.2_01\bin;
17
使用 Javac 編譯程式 C:\work\dbtest.java : 使用者編輯的程式碼
18
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’
19
java 語言範例 結果
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.