Professional Documents
Culture Documents
Tbca Java (Paperno. - 3. 5) Uni T-4: 1.expl Ai Njdbcandal Li T SDR I Ver S
Tbca Java (Paperno. - 3. 5) Uni T-4: 1.expl Ai Njdbcandal Li T SDR I Ver S
Tbca Java (Paperno. - 3. 5) Uni T-4: 1.expl Ai Njdbcandal Li T SDR I Ver S
PaperNo.
-3.
5) UNI
T-4
1.Expl
ainJDBCandal
li
tsdr
iver
s.
2)
Ty pe2Dr i
ver-theNat i
ve-APIDr i
ver:
TheJDBCt ype2dr i
ver,alsoknownast heNat i
ve-APIdriveri
sadat abasedri
verimpl
ement ati
onthatusesthecli
ent
-side
l
ibrari
esoft hedat abase.Thedr i
verconv ert
sJDBCmet hodcallsint
onativecal
lsofthedatabaseAPI.Thetype2dri
veris
notwr itt
enent irel
yinJav aasi tinterf
aceswi thnon- Javacodet hatmakesthefi
naldatabasecall
s.
Anat i
ve-
APIpart
ly
Javat echnology -enableddr i
verconv ert
sJDBCcal lsintocall
sont hecli
entAPIforORACLE, DB2orother.Notet
hat,l
ike
thebridgedr iver,thi
sst yl
eofdr iverrequiresthatsomebi narycodebel oadedoneachclientmachine.
Howev erthet ype2dr i
v erprovidesmor ef uncti
onalityandperformancethanthetype1dr i
verasitdoesnothavethe
overheadoft headdi t
ional ODBCf uncti
oncal l
s.
Advant
age:
Bet
terper
for
mancet
hanTy
pe1si
ncenoj
dbct
oodbct
ransl
ati
oni
sneeded
Di
sadvant
age:
a)
Thevendorcli
entl
ibr
aryneedstobeinstal
ledont
hecli
entmachine.
b)
Cannotbeusedininter
netduethecli
entsi
desoft
wareneeded
c)
Notall
databasesgiv
ethecli
entsideli
brar
y
3)
Ty
pe3dr iver-theNetwork-
Prot
ocolDri
ver:
TheJDBCt ype3dr iver
,al
soknownast henetwork-
prot
ocol dr
iveri
sadat
abasedriv
erimplement
ati
onwhi
chmakesuse
ofami ddl
e-t
ierbetweenthecall
ingprogr
am andthedatabase.Themiddl
e-t
ier(
appl
icat
ionser
ver
)conv
ert
sJDBCcal
ls
di
rectl
yorindir
ectlyint
othevendor-
speci
fi
cdatabaseprotocol
.
Adv antages:
a)
Sincet hecommuni cati
onbet weencl i
entandthemi ddl
ewar eserveri
sdat
abaseindependent
,therei
snoneedfor
thev endordbl i
braryont heclientmachi ne.
b)
TheMi ddlewar eSer v
er(Canbeaf ul
lfl
edgedJ2EEAppl i
cati
onserver
)canpr
ovidetypi
calmiddlewar
eser
vicesl
ike
caching( connect ions,queryresults,andsoon),l
oadbal ancingetc.
Disadv antages:
a)
Requi resdat abase-specif
iccodi ngtobedonei nthemi ddleti
er.
b)
Anext ralayeraddedmayr esultinati
me-bott
leneck
4)
Type4-t heNative-ProtocolDriver:
TheJDBCt ype4dr i
ver,alsoknownast henative-
protocoldri
verisadat
abasedr i
veri
mplementati
onthatconver
tsJDBC
call
sdirectl
yintothev endor-specif
icdatabaseprotocol.
Thetype4dri
veri
swr i
ttencomplet
elyi
nJav aandishence
platf
ormi ndependent.Iti
sinst al
ledinsi
detheJav aVirt
ual Machi
neofthecli
ent.Itpr
ovi
desbetterper
for
manceov ert
he
type1and2dr iv
ersasi tdoesnothav etheoverheadofconv ersi
onofcal
lsi
ntoODBCordat abaseAPIcalls.Unl
i
kethe
type1and2dr iv
ers,i
tdoesnotneedassoci at
edsof t
war etowork..
Adv antages:
a)Thesedr i
versdon'ttransl
atetherequestsi
ntodbrequesttoODBCorpassi tt
ocli
entapif
ort
hedb,
nordot
heyneeda
middlewar elayerforrequestindir
ecti
on.Thustheper
f or
mancei sconsider
ablyi
mproved.
b)Webappl icat
ionmai nlyusedthisdri
ver.
Disadv ant
age:
Atcl i
entside,aseparatedr i
verisneededforeachdatabase.ex-cl
asses12.zi
p(f
orORACLE)
2.Di
scusst
heAPPLETandi
tsconcept
,wr
it
etheappl
etssy
ntaxt
odr
aw:
Cone,
Cyl
i
nder
,Cube,
Squar
einsi
deaci
rcl
e,
Cir
cle
i
nsi
deasquar
e.
1
PRESI
DENCYCOLLEGE
TBCA JAVA(
PaperNo.
-3.
5) UNI
T-4
publi
ccl assShapesext endsAppl et
{
publicv oidpai nt(Graphi csg)
{
/*Cylinder* /
g.
dr awSt ring("(
a) .
Cy linder",
10,110)
;
g.
dr awOv al(
10,10, 50,10) ;
g.
dr awOv al(
10,80, 50,10) ;
g.
dr awLi ne(10,15,10, 85) ;
g.
dr awLi ne(60,15,60, 85) ;
/*Cube* /
g.
dr awSt ring("(
b) .
Cube" ,95,
110);
g.
dr awRect (80,10,50, 50);
g.
dr awRect (95,25,50, 50);
g.
dr awLi ne(80,10,95, 25) ;
g.
dr awLi ne(130, 10,145, 25);
g.
dr awLi ne(80,60,95, 75) ;
g.
dr awLi ne(130, 60,145, 75);
/*SquarI nsideACi rcle*/
g.
dr awSt ring("(
c) .
SquarI nsideACircl
e",
150,
110)
;
g.
dr awOv al(
180, 10,80, 80);
g.
dr awRect (192,22,55, 55);
/*CircleInsideaSquar */
g.
dr awSt ring("(
d) .
Cir cleInsi
deaSquar ",
290,
110)
;
g.
dr awRect (290,10,80, 80);
g.
dr awOv al(
290, 10,80, 80);
}
}
3.Wr i
t eapr ogram andi tssyntaxtoDi splayingI mageinApplet……….
Ans.
Appleti smost lyusedi ngamesandani mat i
on.Fort hispurposeimageisr
equiredtobedi spl
ayed.Thejav
a.awt.
Graphi
cs
classpr ovideamet hoddr awImage( )todi splaytheimage.
Syntaxofdr awImage( )met hod:
1.publ i
cabst ractbooleandr awImage( Imagei mg,intx,i
nty,ImageObser
verobserver)
:
isuseddrawt hespeci
fi
edimage.
Howt ogett heobj ectofI mage:
Thejav a.applet.Appletclassprovidesget I
mage( )methodthatretur
nstheobjectofI
mage.Sy ntax:
publi
c Image get I
mage( URL u,
Stri
ng image){}
Otherr equir
edmet hodsofAppl etclasstodi splayimage:
1.publ i
cURLget Document Base():
isusedt or etur
ntheURLoft hedocumenti nwhichappletisembedded.
2.publ i
cURLget CodeBase():
isusedt oretur nthebaseURL.
i
mpor t
java.awt .*;
i
mpor t
java.appl et
.*;
publi
c class DisplayImage extends
Applet
{
Image picture;
publ ic void i
nit(
)
{
pi
ctur e
= get I
mage( get DocumentBase()
,"
sonoo.
jpg"
);
}
publi
c void paint(Graphics g)
{
g.drawI mage( pictur
e,
30, 30,
thi
s);
}
}
I
ntheabov eexampl
e,drawI
mage()met
hodofGraphi
cscl
assi
susedt odispl
aytheimage.The4thargumentof
drawImage()methodofi
sImageObser
verobj
ect
.TheComponentclassimpl
ementsImageObserveri
nter
face.So
currentcl
assobj
ectwouldal
sobetr
eatedasI
mageObser
verbecauseAppletcl
assindi
rect
lyext
endstheComponent
class.
myapplet.
html
<html
>
<body>
<appl
et
code="
Displ
ayI
mage.
class"
wi
dth="
300"
hei
ght
="300"
>
2
PRESI
DENCYCOLLEGE
TBCA JAVA(
PaperNo.
-3.
5) UNI
T-4
</
appl
et>
</
body>
</
html
>
AdvantageofSwingoverAWT:
Therearemanyadv ant
agesofSwi ngov erAWT.Theyar easf ol
lows:
Swi ngcomponentsarePl at
efor
mi ndependent.
I tisli
ghtwei
ght.
I tsupportspl
uggablelookandfeel.
I thasmor epowerfulcomponentsliketables,l
ist
s,scrol
lpanes,
colorchooser
,tabbedpaneet
c.
I tfoll
owsMVC( Model ViewController
)archit
ecture.
3
PRESI
DENCYCOLLEGE
TBCA JAVA(
PaperNo.
-3.
5) UNI
T-4
f.
set
Size(400,500);
f.
set
Layout (null
);
f.
set
Visibl
e( tr
ue);
}
publ
i
c static voi
d main(
Str
ing[
]
args)
{
new
Simpl e();
}
}
4
PRESI
DENCYCOLLEGE