大型數(shù)據(jù)庫實(shí)驗(yàn)報(bào)告_第1頁
大型數(shù)據(jù)庫實(shí)驗(yàn)報(bào)告_第2頁
大型數(shù)據(jù)庫實(shí)驗(yàn)報(bào)告_第3頁
大型數(shù)據(jù)庫實(shí)驗(yàn)報(bào)告_第4頁
大型數(shù)據(jù)庫實(shí)驗(yàn)報(bào)告_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

中南大學(xué)大型數(shù)據(jù)庫實(shí)驗(yàn)報(bào)告課程名稱大型數(shù)據(jù)庫技術(shù)指導(dǎo)教師姓名學(xué)號(hào)專業(yè)班級《大型數(shù)據(jù)庫技術(shù)》實(shí)驗(yàn)三寫一個(gè)PROC程序,查詢并顯示表Agents的所有記錄。要求定義一個(gè)數(shù)組類型的宿主變量,一次性把所有記錄從服務(wù)器端傳送到客戶端,然后逐行顯示。Java代碼如下: publicvoidselectAgents()throwsException{ Connectionconn=this.getConnection(); Statementstmnt=conn.createStatement(); ResultSetset=stmnt.executeQuery("select*fromAgents"); System.out.println("查詢結(jié)果如下:\n"); while(set.next()){ Stringid=set.getString("AID"); Stringname=set.getString("ANAME"); Stringcity=set.getString("CITY"); intpercent=set.getInt("PERCENT"); System.out.println("aid:"+id+"aname:"+name+"city:"+city+"percent:"+percent); } set.close(); stmnt.close(); conn.close(); }測試代碼: publicstaticvoidmain(String[]args)throwsException{ Stringurl="jdbc:oracle:thin:@localhost:1521:ORCL"; Stringuser="jelly"; Stringpwd="csusoft"; DBOpersdb=newDBOpers(url,user,pwd); db.selectAgents(); }測試結(jié)果:寫一個(gè)PROC程序,根據(jù)用戶輸入的城市,查詢并逐行顯示該城市所有顧客的編號(hào)、名稱和折扣。如果該城市中不存在任何顧客,則調(diào)用一個(gè)錯(cuò)誤處理函數(shù),函數(shù)中顯示錯(cuò)誤信息:“該城市中不存在顧客”。Java代碼如下: publicvoidselectCustomerByCity(Stringcity)throwsException{ Connectionconn=this.getConnection(); Statementstmnt=conn.createStatement(); ResultSetset=stmnt .executeQuery("select*fromCustomerswherecity='"+city +"'"); booleanisEmpty=true; System.out.println("查詢結(jié)果如下:"); while(set.next()){ Stringcid=set.getString("CID"); Stringcname=set.getString("CNAME"); doublediscnt=set.getDouble("DISCNT"); Stringct=set.getString("CITY"); System.out.println("cid:"+cid+"cname:"+cname+"discnt:" +discnt+"city:"+ct); isEmpty=false; } if(isEmpty){ System.out.println("該城市不存在客戶。"); } set.close(); stmnt.close(); conn.close(); }測試代碼:(查詢在Duluth的用戶) publicstaticvoidmain(String[]args)throwsException{ Stringurl="jdbc:oracle:thin:@localhost:1521:ORCL"; Stringuser="jelly"; Stringpwd="csusoft"; DBOpersdb=newDBOpers(url,user,pwd); db.selectCustomerByCity("Duluth"); }測試結(jié)果:寫一個(gè)在循環(huán)中提示用戶輸入一個(gè)顧客ID(cid)和一個(gè)商品ID(pid)(各占一行)的PROC程序。該程序應(yīng)該逐行顯示每一個(gè)提供pid給cid的代理商的aid和由每個(gè)代理商提供的qty總數(shù)的列表。如果提供的cid或pid的值在Customers表或Products表中不存在,則程序應(yīng)該不返回任何行。當(dāng)用戶輸入一個(gè)空行后,程序終止。Java代碼如下: publicvoidselectQTYList()throwsException{ while(true){ System.out.print("請輸入客戶ID:"); BufferedReaderreader=newBufferedReader(newInputStreamReader( System.in)); Stringcid=reader.readLine(); if(cid==null||"".equals(cid.trim())){ break; } System.out.print("請輸入商品ID:"); Stringpid=reader.readLine(); if(pid==null||"".equals(pid.trim())){ break; } Connectionconn=this.getConnection(); Statementstmnt=conn.createStatement(); Stringsql="selecto.aid,sum(o.qty)"+"fromOrderso" +"whereo.cid='"+cid+"'ando.pid='"+pid+"'" +"andexists(select*fromCustomerscwherec.cid='" +cid+"')" +"andexists(select*fromProductspwherep.pid='" +pid+"')"+"groupbyo.aid"; ResultSetset=stmnt.executeQuery(sql); System.out.println("查詢結(jié)果如下:"); while(set.next()){ Stringaid=set.getString(1); intsum=set.getInt(2); System.out.println("代理商ID:"+aid+"QTY總和:"+sum); } set.close(); stmnt.close(); conn.close(); } }測試代碼: publicstaticvoidmain(String[]args)throwsException{ Stringurl="jdbc:oracle:thin:@localhost:1521:ORCL"; Stringuser="jelly"; Stringpwd="csusoft"; DBOpersdb=newDBOpers(url,user,pwd); db.selectQTYList(); }測試結(jié)果:(輸入的ID為空或空格時(shí)推出)在PROC程序中創(chuàng)建一個(gè)PL/SQL函數(shù)qty_check,以一筆訂單的訂貨數(shù)量為參數(shù),判斷該訂單的訂貨數(shù)量是否超過了被訂購商品的庫存數(shù)量。如果沒有超過,返回TRUE,否則返回FALSE。由于在Java中不能創(chuàng)建PL/SQL的函數(shù),所以這個(gè)題目直接用Java代碼實(shí)現(xiàn),Java代碼如下所示: publicbooleanqtyCheck(Stringpid,intqty)throwsException{ booleanflag=false; Connectionconn=this.getConnection(); Statementstmnt=conn.createStatement(); ResultSetset=stmnt .executeQuery("SELECTp.quantityfromPRODUCTSpwherep.pid='" +pid+"'"); if(set.next()){ intstorage=set.getInt(1); if(storage>=qty){ flag=true; } } set.close(); stmnt.close(); conn.close(); returnflag; }測試代碼: publicstaticvoidmain(String[]args)throwsException{ Stringurl="jdbc:oracle:thin:@localhost:1521:lee"; Stringuser="system"; Stringpwd="evefish"; DBOpersdb=newDBOpers(url,user,pwd); System.out.println(db.qtyCheck("P07",100501)); System.out.println(db.qtyCheck("P01",1000)); }測試結(jié)果:寫一個(gè)PROC程序接收代理商輸入的訂單信息,并把它加入到CAP數(shù)據(jù)庫中。要求執(zhí)行以下步驟:(1)提示并接收用戶輸入的訂單信息,包括顧客的cid、供貨的代理商的aid、訂購的商品的pid、訂購商品的數(shù)量qty以及訂單的月份month。(2)調(diào)用PL/SQL函數(shù)qty_check,檢查商品訂購數(shù)量是否小于/等于庫存數(shù)量。如果函數(shù)返回TRUE,則繼續(xù)執(zhí)行,否則結(jié)束。(3)從表products中該訂購商品的庫存數(shù)量中減去訂購數(shù)量。(4)在訂單表Orders中插入一條記錄,其中訂單的編號(hào)和商品總價(jià)由定義在表Orders上的觸發(fā)器自動(dòng)填寫。將上述步驟定義為一個(gè)事務(wù)。編寫一段程序加以實(shí)現(xiàn)。以下是該程序的Java代碼: publicvoidmakeOrder()throwsException{ //用戶輸入: BufferedReaderreader=newBufferedReader(newInputStreamReader( System.in)); System.out.print("請輸入客戶ID:"); Stringcid=reader.readLine(); System.out.print("請輸入代理商ID:"); Stringaid=reader.readLine(); System.out.print("請輸入商品ID:"); Stringpid=reader.readLine(); System.out.print("請輸入訂單數(shù)量:"); intqty=Integer.valueOf(reader.readLine()); System.out.print("請輸入訂單月份:"); Stringmon=reader.readLine(); reader.close(); //判斷是否超過庫存數(shù)量 Connectionconn=this.getConnection(); //開啟事務(wù) conn.setAutoCommit(false); if(qtyCheck(pid,qty)){ Statementstmnt=conn.createStatement(); //減去qty stmnt.executeUpdate("updatePRODUCTSpsetp.QUANTITY=p.QUANTITY-" +qty+"wherep.pid='"+pid+"'"); //增加新的訂單 stmnt .executeUpdate("INSERTINTOORDERS(MONTH,CID,AID,PID,QTY)VALUES('" +mon +"','" +cid +"','" +aid +"','" +pid +"',"+qty+")"); } mit(); conn.close(); }測試代碼: publicstaticvoidmain(String[]args)throwsException{ Stringurl="jdbc:oracle:thin:@localhost:1521:lee"; Stringuser="system"; Stringpwd="evefish"; DBOpersdb=newDBOpers(url,user,pwd); db.makeOrder(); }測試結(jié)果:CAP數(shù)據(jù)庫中的表Customers、Products和Agents中都有一個(gè)列city。寫一段PROC程序,根據(jù)用戶輸入的城市名和表名,查詢該表中列city的值等于該指定城市的所有記錄。例如,用戶輸入城市名Duluth和表名Customers,則顯示在Duluth的所有顧客的信息。要求采用PROC的動(dòng)態(tài)SQL實(shí)現(xiàn)。在Java的JDBC技術(shù)中也存在動(dòng)態(tài)SQL,實(shí)現(xiàn)如下:publicvoidselectInfoByCity(Stringcity,Stringtable)throwsException{ Connectionconn=this.getConnection(); PreparedStatementps=conn .prepareStatement("select*from?wherecity=?"); ps.setString(1,table); ps.setString(2,city); ResultSetset=ps.executeQuery(); //打印結(jié)果 this.printResultSet(set,table); set.close(); ps.close(); conn.close(); }測試代碼: publicstaticvoidmain(String[]args)throwsException{ Stringurl="jdbc:oracle:thin:@localhost:1521:lee"; Stringuser="system"; Stringpwd="evefish"; DBOpersdb=newDBOpers(url,user,pwd); db.selectInfoByCity("Duluth","customers"); db.selectInfoByCity("Dallas","products"); db.selectInfoByCity("NewYork","agents"); }測試結(jié)果:《大型數(shù)據(jù)庫技術(shù)》實(shí)驗(yàn)四創(chuàng)建一個(gè)PROFILE文件pTester,設(shè)置鎖定用戶的登錄失敗次數(shù)為3次,會(huì)話的總計(jì)連接時(shí)間60分鐘,口令可用天數(shù)30天。CREATEPROFILEpTesterLIMITFAILED_LOGIN_ATTEMPTS3CONNECT_TIME60PASSWORD_LIFE_TIME30;查詢目前所有的環(huán)境資源文件及其限制。SELECTPROFILE,RESOURCE_NAME,LIMITFROMDBA_PROFILES

ORDERBYPROFILE;創(chuàng)建一個(gè)新用戶Tester,密碼也為Tester,缺省表空間是CAP_ts。在CAP_ts表空間中可以使用2M空間,指定環(huán)境資源文件為pTester。CREATEUSERTester

IDENTIFIEDBYT

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論