You are on page 1of 27

Topics in Database Systems Lab

PROGRAMS
1. Develop a database application to demonstrate storing and retrieving of BLOB and CLOB ob ects. The document repository will use one database containing one table to store its data. Using the MySQL console application (c:\mys l\bin\mys l.e!e "or #in$% or &usr&bin&mys l "or 'ni! users() create the database and switch to it with the "ollowing commands: create database my*iles+ use my*iles+ ,e!t create the table that will actually store the -L.-/s as part o" the my*iles database: create table my-lobs ( blob0d int auto1increment not null) blobTitle 2archar(34() blobData longblob) blobType 2archar(34() primary 5ey(blob0d() uni ue id(blob0d( (+ ,ow there is one database named my*iles) which contains one table named my-lobs. The details o" each "ield in the my-lobs table are shown below: blob!d" 6n integer that will pro2ide a uni ue numerical identi"ier "or each blob (ie 7) %) $) etc(. 0t is incremented and trac5ed internally by MySQL whene2er a new record is added. blob#itle" 6 description o" each blob in the table) "or e!ample 8My word document about gol"8) or 89icture o" the s5y8. 0t ser2es no real purpose) but will come in handy when 2iewing the "iles through a web page later on.
M.Tech 0 Sem) Dept. o" :S;) <0TM 7

Topics in Database Systems Lab

blobData" 6 binary "ield that will hold the contents o" each "ile that are to be stored in the database. 0n the craeted table) longblob data type has been used) which can hold up to =)%>=)>?@)%>3 characters. .ther binary "ield types include mediumblob (which can hold up to 7?)@@@)%73 bytes() blob (which can hold up to ?33$3 characters() and tinyblob (which can hold up to %33 characters(.

blob#$pe" ;ach di""erent "ile type (such as .doc) .gi") .pd") etc( has its own uni ue content type. #hen a "ile is uploaded 2ia a web browser to a web ser2er (which we will loo5 at shortly() the browser cle2erly passes that "iles type as part o" its headers. This type will be stored in the table so that one can choose to 2iew only speci"ic types o" "iles "rom the my-lobs table. :ontent types are simple strings. The content type "or a MS word document is 8application&msword8) the content type "or a A0* image is 8image&gi"8) etc.

Blobbing Data %it& P'P and M$S(L ) Adding blobs to t&e database
:reate an BTML "orm that allows users to send "iles to the ser2er. 0t must allow the users to choose a "ile to upload) and to also enter a description "or that "ile. inde*.&tml ChtmlD CheadD CtitleD Upload a *ile C&titleD C&headD Cbody bgcolorE8F******8D C"orm enctypeE8multipart&"ormGdata8 nameE8"rmUpload*ile8 actionE8grab"ile.php8

methodE8post8D Ca hre"E8http:&&www.de2articles.com8D Cimg borderE848 srcE8http:&&www.de2articles.com&dlogo.gi"8D C&aD Ctable borderE848 cellpaddingE848 cellspacingE848 bordercolorE8F7777778

widthE8744H8D
M.Tech 0 Sem) Dept. o" :S;) <0TM %

Topics in Database Systems Lab

CtrD Ctd widthE8744H8 bgcolorE8F**>>448 heightE8%%8 colspanE8%8D Cp styleE8marginGle"t: 748DCbDC"ont "aceE8Ierdana8 siJeE8%8 colorE8F******8D Upload a *ileC&"ontDC&bDC&tdD C&trD CtrD Ctd widthE8744H8 bgcolorE8F**;$--8 colspanE8%8D Cp styleE8marginGle"t: 74+ marginGright: 748DC"ont "aceE8Ierdana8 siJeE8%8D CbrD9lease select a "ile "rom your local computer to upload to our web ser2er "or sa2ing in our database. This "ile can be o" any type you li5e. .nce you ha2e chosen a "ile) please clic5 on the K uot+Upload this "ileK uot+ button below.Knbsp+ Knbsp+CbrDKnbsp+C&"ontDC&tdD C&trD CtrD Ctd widthE873H8 bgcolorE8F**;$--8D Cp styleE8marginGle"t: 748DC"ont "aceE8Ierdana8 siJeE8%8D *ile Description:C&"ontDC&tdD Ctd widthE8L3H8 bgcolorE8F**;$--8D Cinput typeE8te!t8 nameE8strDesc8 siJeE8%48 ma!lengthE8348DC&tdD C&trD CtrD Ctd widthE873H8 bgcolorE8F**;$--8D Cp styleE8marginGle"t: 748DC"ont "aceE8Ierdana8 siJeE8%8D*ile Location:C&"ontDC&tdD Ctd widthE8L3H8 bgcolorE8F**;$--8D C"ont "aceE8Ierdana8 siJeE8%8D Cinput typeE8"ile8 nameE8"ile8 siJeE8%48DC&"ontDC&tdD C&trD
M.Tech 0 Sem) Dept. o" :S;) <0TM $

Topics in Database Systems Lab

CtrD Ctd widthE8$$H8 bgcolorE8F**;$--8D Cp styleE8marginGle"t: 748DC"ont "aceE8Ierdana8 siJeE8%8D CbrD CbrD Knbsp+C&"ontDC&tdD Ctd widthE8?@H8 bgcolorE8F**;$--8D C"ont "aceE8Ierdana8 siJeE8%8D Cinput typeE8submit8 2alueE8Upload this "ile8 nameE8cmdSubmit8DC&"ontDC&tdD C&trD C&tableD C&"ormD C&bodyD C&htmlD ,ow an BTML "orm has been created that allows users to send "iles to the ser2er. 0t allows the user to choose a "ile to upload) and to also enter a description "or that "ile. The only di""erence between the "orm abo2e and any other BTML "orm is that the enctype attribute o" our "orm is set to 8multipart&"ormGdata8: C"orm enctypeE8multipart&"ormGdata8 nameE8"rmUpload*ile8 actionE8grab"ile.php8

methodE8post8D This tells the browser that one may be sending "iles "rom the client/s machine to the ser2er) so it should be ready to prepare the headers and stream the "iles to the ser2er) amongst other things. The inde!.html page loo5s li5e this:

M.Tech 0 Sem) Dept. o" :S;) <0TM

Topics in Database Systems Lab

-e"ore the uploaded "ile is actually processed as a -L.-) "irst one needs to ma5e sure that 9B9 has the capabilities to handle uploaded "iles. :reate a new 9B9 script named phpin"o.php and enter the "ollowing line into it: CMphp phpin"o((+ MD <un the script in the browser. 0t displays the details o" the 9B9 con"iguration. There are three 2ariables that we need to loo5 "or: file+,ploads" Tells 9B9 whether or not to accept "ile uploads. Must ha2e the 2alue 8.n8 to accept "iles. ,pload+ma*+filesi-e" Tells 9B9 the ma!imum "ile siJe that an "ile uploaded can be. 0s speci"ied as N,umber o" megabytesOM) "or e!ample %M "or two megabytes. ,pload+tmp+dir" The directory where 9B9 will store uploaded "iles until they are copied&mo2ed. 0" empty) 9B9 stores them in the operating systems de"ault temporary directory. 0" one needs to change any o" these options) one can do so in 9B9/s con"iguration "ile.

,e!t create a simple 9B9 script to capture "iles "rom userPs computer and store them in the created database. :reate a new 9B9 script named grab"ile.php and sa2e it into a directory that the web ser2er can process. ;nter the "ollowing code into grab"ile.php.
M.Tech 0 Sem) Dept. o" :S;) <0TM 3

Topics in Database Systems Lab

#&e grabfile.p&p" CMphp Q"ileUpload1nameE(Q1*0L;SN/"ile/ON/name/O(+ Q"ileUpload1siJeE(Q1*0L;SN/"ile/ON/siJe/O(+ Q"ileUpload1typeE(Q1*0L;SN/"ile/ON/type/O(+ Q"ileUploadE( Q1*0L;SN/"ile/ON/tmp1name/O(+ QstrDescEQ19.STN8strDesc8O+ i"(empty(QstrDesc( RR Q"ileUpload EE 8none8( die(8Sou must enter both a description and "ile8(+ QdbSer2er E 8localhost8+ QdbDatabase E 8my"iles8+ QdbUser E 8root8+ Qdb9ass E 88+ Qs:onn E mys l1connect(QdbSer2er) QdbUser) Qdb9ass( or die(8:ouldn/t connect to database ser2er8(+ Qd:onn E mys l1select1db(QdbDatabase) Qs:onn( or die(8:ouldn/t connect to database QdbDatabase8(+ Q"ileBandle E "open(Q"ileUpload) 8r8(+ Q"ile:ontent E "read(Q"ileBandle) Q"ileUpload1siJe(+ Q"ile:ontent E addslashes(Q"ile:ontent(+ QdbQuery E 80,S;<T 0,T. my-lobs I6LU;S 8+ QdbQuery .E 8(4) /QstrDesc/) /Q"ile:ontent/) /Q"ileUpload1type/(8+ mys l1 uery(QdbQuery( or die(8:ouldn/t add "ile to database8(+ echo 8Ch7D*ile UploadedC&h7D8+ echo 8The details o" the uploaded "ile are shown below:CbrDCbrD8+ echo 8CbD*ile name:C&bD Q"ileUpload1nameCbrD8+ echo 8CbD*ile type:C&bD Q"ileUpload1type CbrD8+

M.Tech 0 Sem) Dept. o" :S;) <0TM

Topics in Database Systems Lab

echo 8CbD*ile siJe:C&bD Q"ileUpload1siJe CbrD8+ echo 8CbDUploaded to:C&bD Q"ileUpload CbrDCbrD8+ echo 8Ca hre"E/inde!.html/D6dd 6nother *ileC&aD8+ echo 8C&brD8+ MD Ca hre"E8display.php8D list the uploaded "ilesC&aD

Blobbing Data %it& P'P and M$S(L ) Displa$ing t&e files


6 "ile repository in2ol2es being able to both upload and download "iles) so create a 9B9 script that will list all o" the "iles in the my-lobs table. The script must also gi2e user the option to download each o" these "iles. :reate a 9B9 script that will display the details o" each o" the "iles in a BTML table with a lin5 to download each one. :reate a new "ile named display.php and enter the code described below into it: displa$.p&p CMphp QdbSer2er E 8localhost8+ QdbDatabase E 8my"iles8+
M.Tech 0 Sem) Dept. o" :S;) <0TM @

Topics in Database Systems Lab

QdbUser E 8proTect8+ Qdb9ass E 8hac5er8+ Qs:onn E mys l1connect(QdbSer2er) QdbUser) Qdb9ass( or die(8:ouldn/t connect to database ser2er8(+ Qd:onn E mys l1select1db(QdbDatabase) Qs:onn( or die(8:ouldn/t connect to database QdbDatabase8(+ QdbQuery E 8S;L;:T blob0d) blobTitle) blobType 8+ QdbQuery .E 8*<.M my-lobs 8+ QdbQuery .E 8.<D;< -S blobTitle 6S:8+ Qresult E mys l1 uery(QdbQuery( or die(8:ouldn/t get "ile list8(+ MD Ctable borderE878 cellpaddingE848 cellspacingE848 bordercolorE8F7777778 widthE8744H8D CtrD Ctd widthE8$=H8 bgcolorE8F**>>448 heightE8%78D Cp styleE8marginGle"t: 748DCbDC"ont siJeE8%8 "aceE8Ierdana8 colorE8F******8D DescriptionC&"ontDC&bDC&tdD Ctd widthE8$$H8 bgcolorE8F**>>448 heightE8%78D Cp styleE8marginGle"t: 748DCbDC"ont "aceE8Ierdana8 siJeE8%8 colorE8F******8D TypeC&"ontDC&bDC&tdD Ctd widthE8$$H8 bgcolorE8F**>>448 heightE8%78D Cp styleE8marginGle"t: 748DCbDC"ont "aceE8Ierdana8 siJeE8%8 colorE8F******8D *ileC&"ontDC&bDC&tdD C&trD CMphp while(Qrow E mys l1"etch1array(Qresult((

M.Tech 0 Sem) Dept. o" :S;) <0TM

Topics in Database Systems Lab

U MD CtrD Ctd widthE8$=H8 bgcolorE8F**D:6L8 heightE8%78D Cp styleE8marginGle"t: 74+ marginGright: 748D C"ont "aceE8Ierdana8 siJeE878D CMphp echo QrowN8blobTitle8O+ MD C&"ontD C&tdD Ctd widthE8$$H8 bgcolorE8F**D:6L8 heightE8%78D Cp styleE8marginGle"t: 748D C"ont "aceE8Ierdana8 siJeE878D CMphp echo QrowN8blobType8O+ MD C&"ontD C&tdD Ctd widthE8$$H8 bgcolorE8F**D:6L8 heightE8%78D Cp styleE8marginGle"t: 748DC"ont "aceE8Ierdana8 siJeE878D Ca hre"E8display"ile.phpMblob0dECMphp echo QrowN8blob0d8O+ MD8 targetE81blan58D Download now C&aDC&"ontD C&tdD C&trD CMphp V echo 8C&tableD8+ MD

M.Tech 0 Sem) Dept. o" :S;) <0TM

>

Topics in Database Systems Lab

#hen clic5ed on the 8Download now8 lin5) the display"ile.php script will be called up) passing the id o" the blob re uested as the blob0d uery string 2alue. :reate a new "ile named display"ile.php and enter the "ollowing code into it:

displa$file.p&p CMphp Qblob0dEQ1A;TN8blob0d8O+ i"(Wis1numeric(Qblob0d(( die(80n2alid blob0d speci"ied8(+ && Database connection 2ariables QdbSer2er E 8localhost8+ QdbDatabase E 8my"iles8+ QdbUser E 8root8+ Qdb9ass E 88+ Qs:onn E mys l1connect(QdbSer2er) QdbUser) Qdb9ass(
M.Tech 0 Sem) Dept. o" :S;) <0TM 74

Topics in Database Systems Lab

or die(8:ouldn/t connect to database ser2er8(+ Qd:onn E mys l1select1db(QdbDatabase) Qs:onn( or die(8:ouldn/t connect to database QdbDatabase8(+ QdbQuery E 8S;L;:T blobType) blobData 8+ QdbQuery .E 8*<.M my-lobs 8+ QdbQuery .E 8#B;<; blob0d E Qblob0d8+ Qresult E mys l1 uery(QdbQuery( or die(8:ouldn/t get "ile list8(+ i"(mys l1num1rows(Qresult( EE 7( U Q"ileType E Xmys l1result(Qresult) 4) 8blobType8(+ Q"ile:ontent E Xmys l1result(Qresult) 4) 8blobData8(+ header(8:ontentGtype: Q"ileType8(+ echo Q"ile:ontent+ V else U echo 8<ecord doesn/t e!ist.8+ V MD 0n the code abo2e the uery string 2ariable Qblob0d is used to retrie2e the

blobType and blobData "ields "rom the my-lobs database. 0" there was a row returned "rom the uery) then its type and actual data are sa2ed to two 2ariables) called Q"ileType and Q"ile:ontent respecti2ely. The header "unction is used to change the type o" content that is being sent to the browser. The de"ault content type is te!t&html) which the browser assumes is a web page. 0" a call to the header "unction is not included) then when the binary data is output it will loo5 li5e garbage in the browser. Lastly) the echo command is used to actually output the contents o" the binary "ile to the browser) which handles the "ile as it sees "it.

M.Tech 0 Sem) Dept. o" :S;) <0TM

77

Topics in Database Systems Lab

These are some o" the screen shots "or how the script wor5s with di""erent "ile types: .or !mages"

.or '#ML doc,ments"

.or MS /ord doc,ments"

M.Tech 0 Sem) Dept. o" :S;) <0TM

7%

Topics in Database Systems Lab

0. Develop a database application to demonstrate t&e representation of m,ltival,ed attrib,tes and t&e ,se of nested tables to represent comple* ob ects. /rite s,itable 1,eries to demonstrate t&eir ,se. M,ltival,ed Attrib,te Representation" create type T..LS1I6 as 2array(3( o" Iarchar%(%3(+ create table -orrower(,ame 2archar%(%3()Tools T..LS1I6)constraint -orrower19Y primary 5ey (,ame((+ insert into -orrower 2alues(/Shilpa/)T..LS1I6(/hammer/)/dri2er/)/nuts/)/bolts/)/5ni"e/((+ select -.,ame),.' "rom -orrower -) Table(-.Tools( ,+

2ested #able Representation" create type 6,0M6L1TS as obTect(-reed 2archar%(%3(),ame 2archar%(%3()-irthDate D6T;(+ create type 6,0M6L1,T as table o" 6,0M6L1TS+ create table -reeder

M.Tech 0 Sem) Dept. o" :S;) <0TM

7$

Topics in Database Systems Lab

(-reeder,ame 2archar%(%3()6nimals 6,0M6L1,T( nested table 6,0M6LS store as 6,0M6L1,T1T6-+ insert into -reeder 2alues (/Shilpa/) 6,0M6L1,T( 6,0M6L1TS(/D.A/)/Aolden <etrie2er/)/$7GM6<G47/() 6,0M6L1TS(/D.A/)/Labrador/)/7LGZULG47/() 6,0M6L1TS(/D.A/)/Yo55er Spaniel/)/7LGD;:G74/( ((+ select -reeder,ame) ,.,ame) ,.-irthDate "rom -reeder) T6-L;(-reeder.6nimals( ,+ select -reeder,ame) ,.-reed) ,.,ame) ,.-irthDate "rom -reeder) T6-L;(-reeder.6nimals( , where ,.-irthDateE/7LGD;:G74/+

update T6-L;(select 6nimals "rom -reeder where -reeder,ame E /6lo5/( , set ,.-irthDateE/47GD;:GL@/ where ,.,ame E /Labrador/+ delete T6-L;(select 6nimals "rom -reeder where -reeder,ame E /6lo5/( , where ,.,ameE/Labrador/+

3. Design and develop a s,itable St,dent Database application. One of t&e attrib,tes to be maintained is t&e attendance of a st,dent in eac& s,b ect for %&ic& &e4s&e &as enrolled. 5sing #R!GG6RS7 %rite active r,les to do t&e follo%ing" /&enever t&e attendance is ,pdated7 c&ec8 if t&e attendance is less t&an 9:;< if so7 notif$ t&e 'ead of t&e Department concerned. /&enever7 t&e mar8s in an !nternal Assessment #est are entered7 c&ec8 if t&e mar8s are less t&an =>;< if so7 notif$ t&e 'ead of t&e Department concerned. #rigger Creation set 6,S01,ULLS .,
M.Tech 0 Sem) Dept. o" :S;) <0TM 7=

Topics in Database Systems Lab

set QU.T;D10D;,T0*0;< ., A. GG EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE GG 6uthor: C6uthor)),ameD GG :reate date: C:reate Date))D GG Description: CDescription))D GG EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE :<;6T; T<0AA;< NdboO.Ntt7O ., NdboO.NSTUD;,T1:.U<S;O 6*T;< 0,S;<T)U9D6T; 6S -;A0, GG S;T ,.:.U,T ., added to pre2ent e!tra result sets "rom GG inter"ering with S;L;:T statements. S;T ,.:.U,T .,+ GG 0nsert statements "or trigger here declare Xu 2archar(74(+ declare Xm int+ declare Xa int)Xatper int+ select XuEusn)XmEmar5s)XaEattnd "rom STUD;,T1:.U<S;+ set XatperEXa&34'744+ i" XmC$3 -;A0, update STUD;,T1:.U<S; set "lag%E7 where(mar5sEXm(+ ;,D else -;A0, update STUD;,T1:.U<S; set "lag%E4 where(mar5sEXm(+ ;,D i" XatperCL3 -;A0,
M.Tech 0 Sem) Dept. o" :S;) <0TM 73

Topics in Database Systems Lab

update STUD;,T1:.U<S; set "lag7E7 where(attndEXa(+ ;,D else -;A0, update STUD;,T1:.U<S; set "lag7E4 where(attndEXa(+ ;,D ;,D

Attendance 5pdation 9artial :lass alterattnd 0nherits System.#eb.U0.9age 9rotected Sub -utton71:lic5(-yIal sender 6s .bTect) -yIal e 6s System.;2ent6rgs( Bandles -utton7.:lic5 Try Dim con 6s ,ew Data.S l:lient.S l:onnection(8Data SourceE.\SQL;[9<;SS+0nitial :atalogED-MS+0ntegrated SecurityETrue8( Dim cm 6s ,ew Data.S l:lient.S l:ommand Dim da% 6s ,ew Data.S l:lient.S lData6dapter Dim ds% 6s ,ew Data.DataSet Dim att E 4 Dim da$ 6s ,ew Data.S l:lient.S lData6dapter Dim ds$ 6s ,ew Data.DataSet Dim cname E 88 Dim da= 6s ,ew Data.S l:lient.S lData6dapter Dim ds= 6s ,ew Data.DataSet Dim da3 6s ,ew Data.S l:lient.S lData6dapter Dim ds3 6s ,ew Data.DataSet
M.Tech 0 Sem) Dept. o" :S;) <0TM 7?

Topics in Database Systems Lab

Dim da? 6s ,ew Data.S l:lient.S lData6dapter Dim ds? 6s ,ew Data.DataSet Dim da@ 6s ,ew Data.S l:lient.S lData6dapter Dim ds@ 6s ,ew Data.DataSet Dim dnoo"stud E 4 Dim hodmailid E 88 Dim "lag7 E 4 Dim n E 88 Dim emailmsg E 88 Dim emailsubT E 88 Dim percentageattnd E 4 cm.:onnection E con cm.:onnection..pen(( Try da% E ,ew Data.S l:lient.S lData6dapter(8S;L;:T attnd "rom STUD;,T1:.U<S; where(US,E/8 K DropDownList7.Te!t K 8/ and cidE/8 K DropDownList%.Te!t K 8/(8) con( da%.*ill(ds%( att E Trim(ds%.Tables(4(.<ows(4((4(( :atch e! 6s ;!ception Msg-o!(8 the selected :ourse is not opted by the selected StudentWWW8( ;!it Sub ;nd Try 0" att CD Te!t-o!7.Te!t Then Msg-o!(8 The entered 9re2ious 6ttendance is incorrectWWW8( ;!it Sub ;nd 0"

M.Tech 0 Sem) Dept. o" :S;) <0TM

7@

Topics in Database Systems Lab

cm.:ommandTe!t E 8update STUD;,T1:.U<S; set attndE8 K Te!t-o!%.Te!t K 8 where( US,E/8 K DropDownList7.Te!t K 8/ and cidE/8 K DropDownList%.Te!t K 8/(8 cm.;!ecute,onQuery(( Msg-o!(87 entry altered success"ully8( / ,ow chec5 "or attnd shortage..... da= E ,ew Data.S l:lient.S lData6dapter(8S;L;:T "lag7 "rom STUD;,T1:.U<S; where(US,E/8 K DropDownList7.Te!t K 8/ and cidE/8 K DropDownList%.Te!t K 8/ and attndE8 K Te!t-o!%.Te!t K 8(8) con( da=.*ill(ds=( "lag7 E Trim(ds=.Tables(4(.<ows(4((4(( / "lag%E7 implies mar5s shortage 0" "lag7 E 7 Then / there is attendance shortage / compute all the parameters needed to send email noti"ication.... da3 E ,ew Data.S l:lient.S lData6dapter(8S;L;:T ,ames "rom STUD;,T where(US,E/8 K DropDownList7.Te!t K 8/(8) con( da3.*ill(ds3( n E Trim(ds3.Tables(4(.<ows(4((4(( da$ E ,ew Data.S l:lient.S lData6dapter(8S;L;:T cname "rom :.U<S; where(cidE/8 K DropDownList%.Te!t K 8/(8) con( da$.*ill(ds$( cname E Trim(ds$.Tables(4(.<ows(4((4(( da? E ,ew Data.S l:lient.S lData6dapter(8S;L;:T Dno "rom STUD;,T where(US,E/8 K DropDownList7.Te!t K 8/(8) con( da?.*ill(ds?( dnoo"stud E Trim(ds?.Tables(4(.<ows(4((4(( da@ E ,ew Data.S l:lient.S lData6dapter(8S;L;:T mail1id "rom D;96<TM;,T where(DnoE8 K dnoo"stud K 8(8) con( da@.*ill(ds@( hodmailid E Trim(ds@.Tables(4(.<ows(4((4((
M.Tech 0 Sem) Dept. o" :S;) <0TM 7L

Topics in Database Systems Lab

percentageattnd E Te!t-o!%.Te!t & 34 ' 744 /Msg-o!(8 H attnd E 8 K percentageattnd( Try / :reate an .utloo5 application. Dim o6pp 6s .utloo5.16pplication o6pp E ,ew .utloo5.6pplication(( / :reate a new Mail0tem. Dim oMsg 6s .utloo5.1Mail0tem oMsg E o6pp.:reate0tem(.utloo5..l0temType.olMail0tem( emailsubT E 8Shortage o" 6ttendance...8 emailmsg E 8US, E 8 K DropDownList7.Te!t K 8 ),ame E 8 K n K 8 ):ourse in which there is shortage E 8 K cname K 8 ):ourse 0D E /8 K DropDownList%.Te!t K 8/) 6ttendance E 8 K Te!t-o!%.Te!t K 8) 9ercentage o" attendance E 8 K percentageattnd oMsg.SubTect E emailsubT oMsg.-ody E emailmsg oMsg.To E hodmailid /Dim s-odyLen 6s String E oMsg.-ody.Length Try / Send oMsg.Send(( :atch e! 6s ;!ception Msg-o!(8Mail sending *ailedWWW8 K e!.Message( / :lean up o6pp E ,othing oMsg E ,othing ;!it Sub

M.Tech 0 Sem) Dept. o" :S;) <0TM

7>

Topics in Database Systems Lab

;nd Try / :lean up o6pp E ,othing oMsg E ,othing Msg-o!(8email noti"ication "or shortage o" attendance sent success"ully to the concerned B.D o" the department to which student belongsWWW8( :atch e! 6s ;!ception Msg-o!(e!.ToString( ;nd Try ;nd 0" :atch e! 6s ;!ception Msg-o!(e!.Message( ;nd Try ;nd Sub ;nd :lass

Mar8s 5pdation 9artial :lass altermar5s 0nherits System.#eb.U0.9age 9rotected Sub -utton71:lic5(-yIal sender 6s .bTect) -yIal e 6s System.;2ent6rgs( Bandles -utton7.:lic5 Try Dim con 6s ,ew Data.S l:lient.S l:onnection(8Data SourceE.\SQL;[9<;SS+0nitial :atalogED-MS+0ntegrated SecurityETrue8( Dim cm 6s ,ew Data.S l:lient.S l:ommand Dim da% 6s ,ew Data.S l:lient.S lData6dapter Dim ds% 6s ,ew Data.DataSet

M.Tech 0 Sem) Dept. o" :S;) <0TM

%4

Topics in Database Systems Lab

Dim mar5s E 4 Dim da$ 6s ,ew Data.S l:lient.S lData6dapter Dim ds$ 6s ,ew Data.DataSet Dim cname E 88 Dim da= 6s ,ew Data.S l:lient.S lData6dapter Dim ds= 6s ,ew Data.DataSet Dim da3 6s ,ew Data.S l:lient.S lData6dapter Dim ds3 6s ,ew Data.DataSet

Dim da? 6s ,ew Data.S l:lient.S lData6dapter Dim ds? 6s ,ew Data.DataSet Dim da@ 6s ,ew Data.S l:lient.S lData6dapter Dim ds@ 6s ,ew Data.DataSet Dim dnoo"stud E 4 Dim hodmailid E 88 Dim "lag% E 4 Dim n E 88 Dim emailmsg E 88 Dim emailsubT E 88 Dim percentagemar5s E 4 cm.:onnection E con cm.:onnection..pen(( Try da% E ,ew Data.S l:lient.S lData6dapter(8S;L;:T mar5s "rom STUD;,T1:.U<S; where(US,E/8 K DropDownList7.Te!t K 8/ and cidE/8 K DropDownList%.Te!t K 8/(8) con( da%.*ill(ds%(

M.Tech 0 Sem) Dept. o" :S;) <0TM

%7

Topics in Database Systems Lab

mar5s E Trim(ds%.Tables(4(.<ows(4((4(( :atch e! 6s ;!ception Msg-o!(8 the selected :ourse is not opted by the selected StudentWWW8( ;!it Sub ;nd Try 0" mar5s CD Te!t-o!7.Te!t Then Msg-o!(8 The entered 9re2ious Mar5s is incorrectWWW8( ;!it Sub ;nd 0" cm.:ommandTe!t E 8update STUD;,T1:.U<S; set mar5sE8 K Te!t-o!%.Te!t K 8 where( US,E/8 K DropDownList7.Te!t K 8/ and cidE/8 K DropDownList%.Te!t K 8/(8 cm.;!ecute,onQuery(( Msg-o!(87 entry altered success"ully8( / ,ow chec5 "or mar5s shortage..... da= E ,ew Data.S l:lient.S lData6dapter(8S;L;:T "lag% "rom STUD;,T1:.U<S; where(US,E/8 K DropDownList7.Te!t K 8/ and cidE/8 K DropDownList%.Te!t K 8/ and mar5sE8 K Te!t-o!%.Te!t K 8(8) con( da=.*ill(ds=( "lag% E Trim(ds=.Tables(4(.<ows(4((4(( / "lag%E7 implies mar5s shortage 0" "lag% E 7 Then / there is mar5s shortage / compute all the parameters needed to send email noti"ication.... da3 E ,ew Data.S l:lient.S lData6dapter(8S;L;:T ,ames "rom STUD;,T where(US,E/8 K DropDownList7.Te!t K 8/(8) con( da3.*ill(ds3( n E Trim(ds3.Tables(4(.<ows(4((4(( da$ E ,ew Data.S l:lient.S lData6dapter(8S;L;:T cname "rom :.U<S; where(cidE/8 K DropDownList%.Te!t K 8/(8) con(
M.Tech 0 Sem) Dept. o" :S;) <0TM %%

Topics in Database Systems Lab

da$.*ill(ds$( cname E Trim(ds$.Tables(4(.<ows(4((4(( da? E ,ew Data.S l:lient.S lData6dapter(8S;L;:T Dno "rom STUD;,T where(US,E/8 K DropDownList7.Te!t K 8/(8) con( da?.*ill(ds?( dnoo"stud E Trim(ds?.Tables(4(.<ows(4((4(( da@ E ,ew Data.S l:lient.S lData6dapter(8S;L;:T mail1id "rom D;96<TM;,T where(DnoE8 K dnoo"stud K 8(8) con( da@.*ill(ds@( hodmailid E Trim(ds@.Tables(4(.<ows(4((4(( percentagemar5s E Te!t-o!%.Te!t & 744 ' 74 Try / :reate an .utloo5 application. Dim o6pp 6s .utloo5.16pplication o6pp E ,ew .utloo5.6pplication(( / :reate a new Mail0tem. Dim oMsg 6s .utloo5.1Mail0tem oMsg E o6pp.:reate0tem(.utloo5..l0temType.olMail0tem( emailsubT E 8Shortage o" Mar5s...8 emailmsg E 8US, E 8 K DropDownList7.Te!t K 8 ),ame E 8 K n K 8 ):ourse in which there is shortage E 8 K cname K 8 ):ourse 0D E /8 K DropDownList%.Te!t K 8/)Mar5s E 8 K Te!t-o!%.Te!t K 8) 9ercentage o" mar5s E 8 K percentagemar5s oMsg.SubTect E emailsubT oMsg.-ody E emailmsg oMsg.To E hodmailid /Dim s-odyLen 6s String E oMsg.-ody.Length Try
M.Tech 0 Sem) Dept. o" :S;) <0TM %$

Topics in Database Systems Lab

/ Send oMsg.Send(( :atch e! 6s ;!ception Msg-o!(8Mail sending *ailedWWW8 K e!.Message( / :lean up o6pp E ,othing oMsg E ,othing ;!it Sub ;nd Try / :lean up o6pp E ,othing oMsg E ,othing Msg-o!(8email noti"ication "or shortage o" mar5s sent success"ully to the concerned B.D o" the department to which student belongsWWW8( :atch e! 6s ;!ception Msg-o!(e!.ToString( ;nd Try ;nd 0" :atch e! 6s ;!ception Msg-o!(e!.Message( ;nd Try ;nd Sub ;nd :lass =. Design7 develop7 and e*ec,te a program in a lang,age of $o,r c&oice to implement t&e algorit&m for determining relevance of a doc,ment ,sing #.)!D. approac& and demonstrate its %or8ing against s,itable data. C Program
M.Tech 0 Sem) Dept. o" :S;) <0TM %=

Topics in Database Systems Lab

FincludeCstdio.hD FincludeCstdlib.hD FincludeCstring.hD FincludeCmath.hD &' in Linu! use cc p.c Glm ( to lin5 to mathematical library ( needed "or log74( ( "unction( '& int main(( U *0L; ' "p+ char 5eyN%4O)"ileN$4O)ch+ && 5ey is the term int n)wordsE4+&&nE o. o" terms) wordsEtotal no. o" terms in the document double t")id")rE4+ && T*) 0D*) <ele2ance int occurE4)total)m)i)T)l+ && occurE total no. o" occurences o"term in document) totalEtotal no. o" documents &' m E no. o" documents that contain the term ( chosen randomely ( a 2al between 4 to total K hence H by (total\7( '& && lElength o" term print"(8\n enter the absolute pathname o" the "ile:8(+ gets("ile(+ i"(("pE"open("ile)8r8((EE,ULL( U print"(8\n ;rror in opening the "ileWWW\n8(+ e!it(4(+ V && counting no. o" words in a te!t "ile....(not 2ery accurate) its an appro!imation( while((chE"getc("p((WE;.*( U i"((chEE//(RR(chEE/)/(RR(chEE/+/(RR(chEE/./(RR(chEE/:/(RR(chEE/&/(RR(chEE/M/(RR(chEE/W/((

M.Tech 0 Sem) Dept. o" :S;) <0TM

%3

Topics in Database Systems Lab

words\\+ V "close("p(+ print"(8\n enter the no. o" 5eywords:8(+ scan"(8Hd8)Kn(+ print"(8\n enter the total no. o" documents:8(+ scan"(8Hd8)Ktotal(+ iE7)TE4+ while(iCEn( U print"(8\n enter the 5eyword Hd:8)i(+ scan"(8Hs8)5ey(+ lEstrlen(5ey(+ print"(8\n 5ey term is:8(+ puts(5ey(+ print"(8\n length o" 5eyEHd8)l(+ i"(("pE"open("ile)8r8((EE,ULL( U print"(8\n ;rror in opening the "ileWWW\n8(+ e!it(4(+ V while((chE"getc("p((WE;.*( U i"(chWE5eyNTO( TE4+ i"(chEE5eyNTO( T\\+
M.Tech 0 Sem) Dept. o" :S;) <0TM %?

Topics in Database Systems Lab

i"(TEEl( U occur\\+ TE4+ V V mErand((H(total\7(+ print"(8\n TEHd)occurEHd)wordsEHd)mEHd8)T)occur)words)m(+ t"Elog74(7.4\((double(occur&(double(words((+ && typecasting id"E7.4&(double(m+ r\E(t"'id"(+ && cumulati2e sum o" rele2ances wrt to each term print"(8\n t"EHl") id"EHl") rEHl"8)t")id")t"'id"(+ i\\) occurE4+ V "close("p(+ print"(8\n rele2ance o" document w.r.t to speci"ied 5eywords is: Hl"\n\n8)r(+ return 4+ V .utput: enter the absolute pathname o" the "ile:c:\tc\bin\3.c enter the no. o" 5eywords:= enter the total no. o" documents:7 enter the 5eyword 7:i" 5ey term is:i" length o" 5eyE% TE4)occurE@)wordsE7=%)mE4

M.Tech 0 Sem) Dept. o" :S;) <0TM

%@

You might also like