Advance-Java-JDBC-1
Advance-Java-JDBC-1
yper of Editions
DTava SBandord Ecition
(OTere JAYA,JAVA SE
I) Tava Enterom'se EdiEicm.
ADVANcE TAVA JEE, J2EE
11) Toya Mico Edition
Java Mobile Edition
Hhe Purpose of different Editions?
Tava Standard EdiH¡n (7E)
->
Sng is a lbraly of Tava
> Swin refers to Htle Tava Swing Librasy
whic is
set of Singre.
gaphical er înte face
CGur) camponents asl tools for buding
dosktopapplications
#Applet
’ Applet PE wed to perform Some hunchion
-> An apple i a Small coaompute pragTan.
thatper forms Speciic task
DS ing TSE ,We can build,
)Standalone. Application
) Sockek Applicatiom.
MVCModel-View-(ontoller
-send data
tibiates
Bain via qetters
Archteture
Controller
Reguest
data Serd
odata vfew- Driver
Model- Modi
U (ontoller -Buires
Mode Data
Repone user
Controller (Brain)> Corntrols decides ho data is displayed
Model (Data Modify) - Data Logic with
View (User Inter taca)’ gelters, settors, toskina
Represerts curent mod state
It takes înput from wer
-) MVc, wich standy for Model -
Vien-Controler
It is a software arhitectura pattun
sed in the design and commony
development f applRcafons
Paricularly
d deskop
in the
appieati on.
Comtext o eb applfcahon
Tt
It f aa woy to organixe stucture cde.
to enkance maintaiobiliky aaalatyo)
and scalability
Package Dedaration:
Padogs
domain etensin, oganizatonerame, project=n .nam. model
domain- extension. cngonieohonyname,projtch-name.Ve
damain- extension, ongpnz aion name. project.name, control er
t¡ edu. qsp.kns. model, edu,9sp. ms. vie weduqpm toyto
tter.
-Domaun Extension &
Commerçal -oovernment webite
îndian woebeite
onorg anizaion
TOsC-
JDBC
Iova
Tava
DataBaleCopsbettt
’henexer wite
e
with datab
faat paqxanm neud ta cannmuaiakinterface nead
standi ai an
TORO PI
Tava nognam & datoa bale.
between J DBC
Rrogramming
API - Applicatin Taterface.
An API is set of rules prototols thot
dlefines oAterat softwore Componenh
how aertnt
should interaot with each ohr
Tt provides structured atandarize
fox different aplicaion moldes
4,0 mmunicate exchange olata
Data Datu rawfa ct which descibel
attributes of an entiky.
Data Stcxage Solabioni
Data storage is
Anith whare bow edere informatoni
digilal sydtem
) File Shonage
) Database
'DATE
J Less compezky o
V Iv) Moe
Lacndlald
aandle
t Database medium
Databate is place stutetured
whene gtoe data
Systematic manner
Tupes oE Databae
DRelaticnal Database ctoe
i s a soft ware where we
I
tables er relations.
data
iented databae
Objeck
) I o tuare where wwe ttore
date fom
DATE
t) Grraph Datahae.
) Dishributed Databae
soFtwure which
dictibu
aleng different localions
V) Data Ware houie
I fomausfor fastee quy
execuioo
Large amount
x) No SQL
As
anga
Dotabaje mutiple
Can be
)Execution SLatement
NClose Conneckiorm
'DAT
Fesizcs&al
Search PgAdmin > run os od ministrator root
pawod
Cmeate Databae
cneate table
Dorop Doatabaye
#MAVEN Project -
Why do we need to Cmrtate MAVEN proie
laile Jog king with TDRc
Creating MAVEA Qrojeck while wrking
TDÁ offers Seveial adontages.
-. 9 Dapendany Management. dowaloadeinclude
Vautam aflcally
MAVEN wils Vautomacally
cies enseike athat buileprajecttione
required dependen ciu
has the Gbyaries
necessary run-time.
t What it
dependency
We necd to modify i "pom.xml" ile by
adding dupendancies int it.
In conlert with MAVEN project.dapendana
Tn
in the pom.xm" ile rfes o external
ibrary r module tat
madude that your praject elies
Intide "pom.ximl" in <dependepcies >
<ldependencies we an oefinc dlapendencdes.
ieWe nead to add dapendencies to
depeoding
datahale that we
establsh Connechi¡n witb.
In Caie we are
we will Poclgre dependenee
’Ovunerahibties
mniaeposikeny postamigl TDBCpastoses ’ more wsage
Diver ’latest versio
) Establish Connection -
Connectin connectin = DriverManager. qet ConneeEion
) Crreaion o 8tatement:
-).To cse te statement we Can Connechin
abject
IE netwns staltment object.
Skaktment stateonent : connectin.create Statmah
v) Exteutin of Statement i
xe cube. qussy statement
statement. execube ();
v) Uose Connection :
-> CoDDection. close O:
T Shecla
Laila
Alok
frorn doakag
Wehae multipk menode ko fetch data'uwith
dieent datatype
Paramoer
eturnt
columnvauldata
9ek Int Cnt columnindex)HhroMs SqLEXCETIDN
qet Stin (Sting colurmn.ngn) inos GoLEXCE PTI6
qet Double (oub le colemnindex)thtolu SpLEXCEIO
getlong () , ete. colinda ot vutd
columo number
) For thic method, we Can pasS col
which we call index.
Notei Index starte Arom 1. These yet ()
overloaded meihods. hese
methods Cre as wel|
methods Can access columnname.
column index.
data from database
# Cases wbile PetchinaRecord
Case Ii Single
Case T :Mutiple Record
5It doesn't matter how
reconde
aere e Lave to ese loop only
4he Cales
’I oil be used
wio 2
2 Driver diver
DirerMa naqer. egis ler Driver( Jriver)i
This is More gener alited way a we
ofier class.
We Can have mulliple clapencies io pamexmly
omdatabale. We can cannect Java
depending
praga witmudkinle databases
9cees pariculat Drver
Establish lonnection
thee ting
way ii Create onnection
arauments
DriverMavager.qetlonnection(Gting ul, Strirg er
shig
i postqresg!:/ocalhost:s432 /db-Mame
JJbc whichever datbase we an
fay that databaje
wl (wniversal resource lo coteusin
we fare going to have speciic
er name
pauswod( posswod of database)
qetlonneetion) throms sqlExceptiom, T s checked
Exception port namber 3306
has
mysq
get Conneotion () eturns o nnection object.
what is Cannechion 2
Connection gn Interface
Connectin present loside fava. sql packaae
DATE
qetcomnectim ()
Abconlig-propertier
Caoeate VnitetnptStrzam fteINpukshream
-) FileloputShram
fileInpatStheam Alelnput Stream ntw
Create
EileInputStream
a ictass 9n Java which s wie to rad
dato fem a Pile.
Propeeties
It s a clase io Java hat epesents set ot
prnpertiesof ten uied fox cnfigurakion settin
+Tiransition rom stotement' to 'PreporedStatemsek
data to be
s)Use 'pstm' objeck
ahject to set ar to
setomethods
feed
storedUsing Cindexlcal-name, Yalue
Ptm. set Datatype
4) Execute pstm
> pstm. execute CO
eparedlstotenunt 9(6-call-stored
towe 0eed
do PrOcedre)
To execuke' dlynamic qwenerfit we naed
eKecute clynamic quories,
it's 'Delimeters'
to wite Que alons with
dalimeter
hr erery fietd,be uil have e
> We hasemutigle sete) methods deendig
datastm
> Execute
bypewlich holds key vale
cute
# exeeute
8totement:
DRG providet 3moinoehoda fox executing
sal statement each servinga Aereutppot
metlod. Thia mek,
query using lexecutes)
Oexecute
versalie and Can be esed
statement.
boolean value that ini cates
O,IE eburn fetched cr not.
un be
hether Result Set Can object can be
ResutSèE
CReturns rue
fetched, eturns folse if there is no
IT
t f oot
meant for executing sql ELECT
qurie, nlichinetieves data fromdatubase.
It retum Tnteger repncsenting the mumbr ok
afecked
Alote If we by to Me
wie ezecuteUpdate ()0 mehod
fos SELECT quegit
uetit thnows sgl exception
wita an errór eASage indicotins 4hat
hie mehod appzopiale Ear
Thit because executelpdate () retuns
number ofows affeoted by the
statermenk, which does not make any
Sente fr sELECT bype query ad it
daes not Modiky
Namel
Return boalean int Resultset
(tru ResultseB Fetch) (no. of modified rowg) (interfo
fadse Restsek
Creatt
Read
X
Update
Delete X
need to wse
To Fetch olata/value from cord we sQLEKCEPITION qety tho
getInt (int column Index) thmows
Rarameter e aguments ( column indax ¢otmn heim)
Cal indey not tabue era.
id
e ! rturn! col vat
retumimttl
+| How Resultset Works EXCEPTIGN
created o table, in whih we
Suppose have ta ftoh
I want
have multiple records and we ELECT
these rec¡nds totoc
happen, we necd
)We wil "erecute(ery
Resull set
e
retuen fram dakabae
return
halding data
)l Reswtset i halding a CuO.
V)
v he cuts
Taitally his wwon'tt be pointing towand
any recordi
to fetch cod so, we
I nan
method.
poinking towade ang re coxd1
starts
starts poanion,
pion,wn when we try to
kteh data ustng qet c)method
# Batch Execubion
Batoh Executtorn
bucket