Tbca Java (Paperno. - 3. 5) Uni T-4: 1.expl Ai Njdbcandal Li T SDR I Ver S

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

TBCA JAVA(

PaperNo.
-3.
5) UNI
T-4

1.Expl
ainJDBCandal
li
tsdr
iver
s.

Ans. Jav aDat abaseConnect ivity(JDBC)def ineshowaj av aprogram cancommuni catewithadatabase.JDBCAPIhas


twomaj orpackagesj ava.sql andj avax .sql.
 
Ther eare4t ypesofJDBCdr i
v ersav ai l
able. 
1)  
  
Type1Dr iver
-theJDBC- ODBCbr idge:  
TheJDBCt ype1dr i
ver ,
alsoknownast heJDBC- ODBCbr i
dgeisadat abasedri
verimplementati
onthattheODBCdr i
ver
toconnectt othedatabase.Thedr iverconv er
tsJDBCmet hodcal l
sintoODBCf uncti
oncall
s.Thebridgeisusual
l
yused
whent her eisnopur e-Javadr iv erav ailableforapar t
iculardatabase. 
Thedr iverisimplement edi nt hesun. jdbc.odbc.JdbcOdbcDr i
verclass. 
Thedr iverisplatf
orm- dependentasi tmakesuseofODBCwhi chinturndependsonnat i
veli
brar
iesoftheoperat
ing
system.  
Adv antage: 
Almostanydat abasef orwhi chODBCdr i
verisinstal
led,canbeaccessed.  
Disadvant age: 
a) 
  
 Per f
ormanceov erheadsi ncet hecal l
shav etogot hr oughtheJDBCov er
headbr i
dgetotheODBCdr i
ver

b)  
  
TheODBCdr iv
erneedst obei nstal l
edont hecl i
entmachi ne 
c) 
  
 consideringtheclient-sidesof twar eneeded, thismightnotbesui tabl
eforapplet
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
>

4.Expl aintheconceptofSwi ngandAWTandal sothediff


erenceofAWTandSWI NG…………
Ans.
JavaSwi ngt utori
al 
isapartofJav aFoundati
onClasses(JFC)thati usedt
s  ocreat
ewi ndow-basedappli
cat
ions.I
tisbui
l
t
onthet opofAWT( AbstractWindowingToolki
t)APIandentir
elywrit
teninj
ava.
Unli
keAWT, Jav aSwi ngprovidesplatf
orm-i
ndependentandli
ghtweightcomponents.
Thejavax.swi ngpackagepr ovidesclassesf
orjavaswingAPIsuchasJBut t
on,
JTextFi
eld,JTextAr
ea,JRadi
oButton,
JCheckbox, JMenuet c.
Dif
ferencebet weenAWTandSwi ng
Therear emanydi f
ferencesbet weenjavaawtandswingthataregivenbelow.
No. Jav
aAWT Jav
aSwi
ng
1) AWTcomponent
sar
e pl
atf
orm-
dependent
. Jav
aswi ngcomponent
sar
e pl
atf
orm-
independent
.
2) AWTcomponent
sar
e heav
ywei
ght
. Swi
ngcomponent
sar
e l
i
ght
wei
ght
.
3) AWT 
doesn'
tsuppor
tpl
uggabl
elookandf
eel
. Swi
ng 
suppor
tspl
uggabl
elookandf
eel
.
4) AWTpr
ovi
des 
l
esscomponent
s t
hanSwi
ng. Swi
ngpr ovi
des morepowerful
component s 
such
astables,l
i
sts,scr
oll
panes,col
orchooser
,
tabbedpaneetc.
5) AWT doesn'tf
ollowsMVC(ModelVi
ewCont r
oll
er)where Swi
ng 
fol
l
owsMVC.
model represent
sdat
a,vi
ewrepresent
spresentat
ionand
control
leractsasani
nter
facebetweenmodel andview.

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.

5.WAPt odemonst rateAWTwi thinheri


tance……………
Ans.
i
mpor t 
jav a.awt .*;
  
class  First ext ends Frame

 
First()

 
But ton  b=new  Button( "click me" );
  
b.set Bounds( 30,100,80, 30) ;// 
setting 
button 
positi
on  
add( b) ;
/ /addi ng button  i
nt o frame   
setSi ze( 300,300) ;
//fr
ame  size 300 width 
and 300 hei
ght 
 
setLay out (null);
//no lay out  
now  by defaul

BorderLayout 
 
setVi sible( tr
ue) ;/
/now  f rame  wi l
lbe vi
sibl
e, 
bydefaul

not vi
sibl
e  

 
publ ic static v oi
d mai n( String args[])

 
First f=new  First()
;  
}}
 
 
6.WAPt odemonst rateSWI NG…………. .
Ans.
i
mpor t 
jav ax.swi ng.*;
  
publ ic class  Simpl e 
{  
JFr ame  f;
  
Simpl e(){  
f=new  JFr ame( );
  
JBut ton  b=new  JBut ton( "click");
  
b.set Bounds( 130,100, 100,  40) ;
  
f.
add( b) ;
  

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

You might also like