0% found this document useful (0 votes)
6 views

Java Programming Part-9 (JDBC Programming) Lecture Notes - ance

The document discusses the use of JDBC (Java Database Connectivity) for connecting Java applications to various databases using different types of drivers, including Type-1, Type-2, Type-3, and Type-4 drivers. It outlines the advantages and disadvantages of each driver type, as well as the steps required to establish a connection, execute SQL statements, and manage database interactions. Additionally, it provides examples of connecting to an Oracle database and executing SQL commands within a Java application.

Uploaded by

vogag38783
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
6 views

Java Programming Part-9 (JDBC Programming) Lecture Notes - ance

The document discusses the use of JDBC (Java Database Connectivity) for connecting Java applications to various databases using different types of drivers, including Type-1, Type-2, Type-3, and Type-4 drivers. It outlines the advantages and disadvantages of each driver type, as well as the steps required to establish a connection, execute SQL statements, and manage database interactions. Additionally, it provides examples of connecting to an Oracle database and executing SQL commands within a Java application.

Uploaded by

vogag38783
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 13
i econ | % Dibreduction te TOBE 2 | > Tn leday's Scenario, Many enterprise level applicalons heed to Mirae With databases a stewny wwloranton. | 5 For Tis purpose, We wed om APT Complication prigyam ming Tulerface) ie ODBe L open Dalabate Connedivill ). 3 The ODBC APT was The datsbate APL te conned- and enews query With We dalabate + Buk, opBe API “Wes opee inc language Che plakie dependent dvver Which 1¢ halle and unsecurad)+ > That uv Why java has defined Wal utes IDBO divers the own APD, called cw ‘apre (tavo. Palabase conmokivilg ) + -tten fm Java language). ble Gt 3 the TpRc doves ave MOVE compet ote communi Caton cone om th Jove. Apalne to pevide dala be a jevo pT te 4 exewle anergy Wh > apBc th the dalabote. Ipwe APL Utes Yabo dvvers fe connect dakabose + | > anec suppl a Wide level of podabilil, ant Tose | ie simple aud easy to use- | vy Needs a Spetitic diver) > In IRE APL, & pragyanme ts peutic dolla bate + | te connect i RDBMS Diver | estore sane einaiepapal | ovale oracle. ydbe - diver « Ovocke Driver | oo | MySQL com. mysql sjdbe «Diver SyBose com» Sybase. jbbe . SybDrivey Gar Sewvet | com- micvo soft.yd be + Sql Server DB2 com. tbm.dbr+ jdbe- ne-» Derdaver | «List ch Some popular Driver. Scanned by CamScanner * apee Archi! The main-findion oth The apge is to provide a glsvdayd abshaction for “ave applications te communi cadiom niTh database ¢ fet ava Applicaton pee | APT | Driver [paver wage | - d sg Be] vole ail u ; at 29:- the Ise Avchledioe ns Shon wo Here, The Jove application iat wont to Communicalé With a dalabote hat to be progvammad using Jpre APL: The ‘Tore Davey ib sraguaved to process tra SOL “veguesle and generele the neesulls. ; he TDRE dyivey hat fe be ply: om im tanl- vole 19 conbiiclina. Te Diver” Mavagey uses ete tively connet™ speufee databases “5 Type Davey is a Soflware comporouk- Hhok enables java appicaton te vbyauk with he dalabote - Some Spoke te DBC dvvers Ye With Scanned by CamScanner i Theve ave 4 Types of ape dvivers, tose ave, > Type -! Diver ( JoRe- oppe badge vor) > Type - 2 Drive Cpatial spec driver) ‘Ad leware) | et database comedy) \ > Type ~ 3 Driver Cpuve java driver toy Mi > re 4 Driver (pure java dvvey with div % Type-| Diver (IDBe - ODBC Isddge diver) = wohl ae, lodge bekween Tyee | The Kpe -1 driver charncms Such as Opec. — | amd offer dolabase connedivilg me The Tpge-opwe badge dvivey uses ODI the dolabote » Tre gpgc- epee bridge dvivey © tut Te ODBC mathod calls - ac. dyer fe conneat- owvert. pee te melhod calls Jove Applicaton i apge Apr rh cat IDRC Davey Managet dpgc- opge bridge avev OPBe Diver vendor Pelabate Libary | sidge OVO gig: appe- OBE & Scanned by CamScanner Advantages : x Easy fe use- & Com be eatily Conned@d to any dalabate - Disadvanliget + X per-famance dagvoded becaute layge number ob trans ~lakions (ie appe calls fe opee calls). client ¥% The opge dvvey veods te be insalled on the Machina. * Type-2 Diver Cpovtial IoRC dvivey) :- ies s the clienk - Side Liby called as Nokive- APL dwver. ints Maltve. callt so tt is The Wpe-2 dvivey use tie database So Ths chiver 1s alto converti Spac wmelhod colle This driver is ek whatten endively i Java, A me database Apt. Te called as partiol TOBE dvver~ Teve Application apee apt TRE Diver Monaget pg Nakive APL dvivey Scanned by CamScanner | Ravawlager: x prefamance upgraded tan apge-opbe bridge river. x cuitatle fe wie With Sever Side opplicobiins Digadvawlag: es | ods to inslalled on te cach clWeuk Modine x tis Nahive chivey ne ds to be indatled on clieut Moc kine, A The Vendor client Library nem the application ye the apaication the cost af Nv oTk way imeyrate on differant platforms « Weeds te van % Type-2 Driver Cpuve Jove driver Jer eniddlewote ) I tre type-3 davey & completely ienplemented #9 30M | is a pure Java GDGC dvvey rid’ hence ik server) le ware Capplic ahion or indevedly ine tae vendor cabled as Nekwork prootocal | The type -3 duvet uses c calls divedly go ik ts that converts TDG ~cpeurhe dobibote profecel - dvver- seve. Appbeadon dpBe APT [ Spee Paver Managey Nekuork protacel paver Middlentave Vewdor yb Scanned by CamScanner | Advonlages ¢ | | vw no clenk cide Ubyary is ~eguivad on clienk Sida. | and auls downloadable - x pave Java dvvers | Disadvaubigers a Nebwork Supgork 1s Yegul is costly compavad to cthey dvivers« \ X “Type -Y Davey Cpave_ ove chiver, with deyoet_dalabase. Connedlag)- ddver, Which converti! databose profecel | vad on cliewk Machine. K This dvivey The type -4 dvver is a pave Jove Th vendor Speke pre calls divedly inte thin dvver- m as that why if ib Kou dave Application | Ipec ArT TpBe Diver fae Tun Diver —, Dolabate Server . Fig Tin Dvivev- pdvoulaiges : ud ants daouloadable. x Ths divey 1s quer Java dvvey oa x Beller performance thaw all other drivers ne No Sollisave ts vepuved ab cliewk sida ov pisadvawlages : x Drives depends on tla Dalabate - ger Ver Side « Scanned by CamScanner x Dolabase Progamming using apRe :- apec Apr, avo used by a Java applicabion te communt cate ulith a celabate. Ga other words, tle use gree connedivity code tn Save application te communicate with a dolabase + There are 5 sleps te conned omy Sova application With Tie database WM Java Using JDBC. “They ave ot fellas + Step: Regisley tke driver closs step 20: Creating connedton shop 2: cvealivg slatémewt step 4: Execubing sar Slalemonk: | step 5.1 closing connectdn. | | x sep 1 :- CRegisler Ie doiver class) an se we | Jn This step, ile vegisler The dviver class With cnive * by using forNawnet> wothod oF class class + Syloxt clacs -forname C Davey class Name) ajdbc dviver- vache Driver’) | Exarnple: Clases eforName Covodle x Slop 2.:- (cvaaling connaton) Tn ‘this step, ble con Create o connerto | sever by using getConnacton C) method & DiverManaget © Syntax: gekConnetion (sting orl , Sing Mamie, shiny ad) | | wy with dalabate tase. | Example: * jdbc soractet thin t @localhost +152 1:xe", “suglena, Yodwein®) * \ | | Connection con = DrverMamager get Connection C | > Sep Bi- Covsalivg statement) after the connedkin made, Wa need fo cxanle the slakwert obged- te eneute tte sau slatemeult. ! Scanned by CamScanner 9 The CyaataStatemauk ©) wetiod of Connection iulayface is used te cane slakmenk. this slalement object is sponsible fo exeule sat sblements with The dolabate Ayrton: x: Cyaale Statement O | cravegle alament shat = con. Slatemeul O; x slip Ur- Cexeusbing sor slalementi) Alter the slalament object crated, it caw be usted | te enctuke the Sar statement by using execute Updo OO | create duary) method of clatewwnt interlace * The enceteQuevy method i oaly uted te encute | | SELECT slatimeult - | all The enetute Update meted is used te eneule cat cbalamouls except SELECT sletements Syrlx: enecale Query Cshivg qe) enewke Updale Cshing query) Bamlet using nemo Query Shing que =“ Select * fever emp" s Resatheek ve = cla. ements Query (query) | [using enersle Update 0 dt inks emp Valuer (sou, "Madbut,24) J Shing quey 2" inde | shal» enctuke Update (Quevy )s “x step St Cclosivg the connection ) | Adler enetufing oll tie SOL clatemenli and obtaing Te the Cel6fon- vosutl, we need te clase the connedion ond release close) wathed ec Connedion interface ce used te | close con. closec) | Scanned by CamScanner The close the Connedin 2% Example :- Cconneckivily sith oracle database) or conneding java oppbcation WTR The oracle dalabase, te need fe Know -follewing inermakon 15 perform dala bote comnedivily with ovacte+ | \5 | | Tq Ths example kl ove using Ove bo We nosd to Knew -fdllawing iv-forwodion duvey class by ovecte dallabate is * pyaclevjdbe «chivar. OrededraveY dev Te oracle 104 dolabase che 10g os the database, dor th oracle dalbast «| x Davey class! The ® Connection URL? the connedtion URL | te Ske + oyocle t thin t@local hos: i521 2xe" + | Where gabe Whe APT, ovocle is the dalabase, thin is the d¥vey, Lecallhost & The Servey name on Which erode is YUnning , 1921 is we is The ovade Sewice Mame - % USemamet The default usevname for Me oracle database is “sylem4" patiword is given by the user ab te time ck imstalling tke ovale dolabate » the pork number ond x password t 3 To Connect ova application with Ime ovate dokabase oydbetrser ile is yeguived to be loaded . = Treva are two ways te load the ofelbely cfollass avy one. oy two ide? 1. posle The oydbelte- tor ajo file wa nerd © Bile in “Jove. [are] Gblet” fldew 2+ Seb clascpath piestly, Search The ajdbety-joy ble When go “java,/fre| ub] ext” Adday ond paste the tov fle heve- for) Sak chose path 5 To sak classpath, gots ewvironas : wick on ves [b+ In Vosigble Mame urls classpath and ( Voveble value paste the path ts ajdbery -jav by appending pidbeluser ses as Wp t\ovadexe Vapp\ ovacle\ praduck \ 1o-2-0\ sewer above Nopdbetyeys 5. ets Vowable then Scanned by CamScanner | & Excomple i Lelle first Crsalé Fin ovate database» a table awd Msert tuo of wrove records mame varchar? luo) foal id number 0), qu> create fable empl ae Hane DDS spl> insert inks emp veluet C501," Medhu', 30)? gars insert tate emp Valet (Sor, ‘Havi', 32) gat> insert — into emp values ( S02, "ott, 335 _pueniel? conned Yove cagplication With Ovacle database for Seledhng | oy ebbing, dab» cadkData +jo¥a | import ovassgl %? iagore jove.-DAL.%: | class Seleupate € be slalte void main (Sting ovgst2) t | Wy Cn slept load Te diver class \ Class foynlame Clonaele “ithe diver vatle Diver") ; Wop 21 cvaole tke commedion objed Conneckivn con “ydbe :ovnde + wer managey get Connection ( Smt @locathote1S21 xe", “oyslew"," advuia'S + ‘step 3: cxeate The stalomenk objed Slalemenk slat = cone Cvante Statemenk (9s W Slep 42 eneude guery Retulkce yy = stat enetale Query (“Select * dom emp") 5 uskile Crs. mexbO) . t “ . 3 « systema. eu. println Cvs. getTuk ) + ye. gutsting + a 5+ get hing@2)) 5 3 tistep S: close Te tonnedon objede con. closets 5 | otek CEneaphon €) J Systm smab-piatl Le} i Scanned by CamScanner output: Die Jovac selecbdalas Jove pia jeva Seled-pata Sor Madhu x Sox Hawi $03 sob 33 sms? conned Jove applicakin with oracle database efor twlevtiy | data. ieqpork geva-Sal 3 import java SRLS class TnsertDala public Sfadie void main Ching avgst3) { hy chiver. gvackevvet ngs Class fortgne. C "oyacle «jdbc: Igonnedkion CU jdbe + ovacle + (hi Connedon con = Drivermanogy qe! t@ locabhost : 121 2x2", Sgyslemn™, Nadkwita!) 5 Statemant slab = con: creat Staldwerk 1; ghat. eneualeUpdele Cin ser = emp velues (504, ' Gavesh’, 283)! Syslewn- out pinkle (* Susevlad «+ con, closeors 3 caléh CEncagtion ©) t ; system out panty C2; 4 i outpuk: Di\> javac Talertdata «save Di\> java Stet dala. Ansevted +++ Scanned by CamScanner % program: java application ulith oracle databate tor update cela.| Updelecials | vapor Java Sql ee; Import Jova-VHL closs Updatedata t public static void main ( Sting avg st3) { bey { class forniame C"ovacle wdbe- diver. oracle Diver J; Comedtion con = Diver Mamages - gpd adbesomle trims @ localhost: isa zxe.", “system”, “odrain") 5 Statement stust = Con- Cvaate Slatement (5 Sit. enevate Update ("update emp sek age 38 Where Syston cook printla C updabid + - ="); con: close 1; id= $03"); coleh CEnoptin ©) it et System: cubs pyinth (" Enteption +205 eo Dt/> jovac Updalednla .yove. p:}> javo Updaledalr Updolad vo + + % DraverMovaget _Closs | class 3- The DaverManager class au as an iwlherface behooen wey ws thal ave auctiable oud, and davers. Tk Keops rack de the diver jalabata and the anpop™l haudles establishing a connedtion beweom a calé dave. Scanned by CamScanner

You might also like