0% found this document useful (0 votes)
39 views25 pages

Ajp Manual

ljkjh hjg khgj khgj khg j

Uploaded by

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

Ajp Manual

ljkjh hjg khgj khgj khg j

Uploaded by

itachisan973
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Advanced Java Programming (22517)

demonstrate variouS mouse


program to
Practical No. 11: Write ausing MouscListener and MouseMotion
events
listener interface.

are used to
1. Practical Significance: MouseMotionListener interfaceis clicked,
The MouseListener and are created when the
mouse implementdropped.the
dragged,
that
different types of events a component. and perform
some
action in that
released, entered and exited inUser to handlethe events
the
These two Interfaces lets
event.

mathematics, sciences aand


II. Relevant Program Outcomes (POs)knowledge of basic basic
Basic knowwledge: Apply related problems.
computer group Programming knowledge to
engineering to solve the Computer solve the
Apply
Discipline knowledge:problems.
computer group related perform experimentsand practices,to use the
practice: Plan to
e
Experiments andcomputer group related problems. technolooia
results to solve the
relevant Computer programming / and
tools: Apply the limitations.
Engineering understanding of and team
tools with an Function effectively as a leader member in
work:
IndividualIand Team
diverse/multidisciplinary teams. effectively in oral and written form.
Communication: Communicate

Competency and Practical skills concepts of Java.


III.
stand-alone applications using advanced
Develop web and develop the following skills:
is expected toevents of MouseListerner
The practicalimplement the MouseMotionListener.
1. Able to events of
the
2. Able to implement
Relevant Course Outcome(s)
IV. events in java programming.
Develop Programs to handle
Practical Outcome (PrOs) MouseListener and
V.
demonstrate various mouse events using
Write a program to
MouseMotionListener interface

Outcome(s)
VI. Relevant Affective domain related
measures.
1. Follow precautionary
2. Follow naming conventions.
3. Follow ethical practices.

Minimum Theoretical Background the user


VIL.
java's MouseListener interface allows the user to handle the events when
events are MouseClicked, MousePressed.
The
performs some events using mouse.The released.
MouseEntered, MouseExited, and Mouse

The list of available methods are:


1. void mouseClicked(MouseEvent me)

Maharashtra state Board of Technical Education


Advanced Java Programming (2251l7)
MouscEvent e)
public void mouseEntered(
.setText("'Mouse Entered");
MouseEvent e)
publicvoid mouseExited(
I.setText("Mouse exited");
MouseEvent e)
public void mouseClicked( clicks:"te.getClickCount():
I.setText("mouse clicked(# of

XI. Result (Outputof Code):


:Nouse Demo - DX
Applet viewer
Applet
uello
"ouse
Appie stoited

XII. Note: Below


Practical givenQuestions
Related are few sample questions for reference. Teacher must design
of identified C0.
to ensure the achievemnent
more such questions so as MouseListener and MouseMotionListener
I. List various methods of MouseEvent
2. Do all components generate the coordinates of MouseClick
3. Write the steps to obtain the
MosueEvents
4. Write the steps to register for
(Space for answer)

Nethod6 o Nouse i9teheY


Ovoid moUse \iCKed( NoUSCFUent e)
2oid mouse Piessel (NoUSEUPht e)
2) void mouse leosed ( Nousefuent e)
9 yoid mguse fhtereo( Housefuent e)
6 uo id m00Se ExitedC MoUG eEuent e)
.s***

( Nethods o Nouse Notion listere


0od mo USe D10gge dC Housefuent e)
.e*****e**********.***..s.*.***.*e.*****...

mOUse oued C oUSe Euopt e)

60
Maharashtra state Board of Technical Education
AdvancedJava Programming (22517)

)Not all Component


. g e nero te NoU6event.

to
Obtoin the coodinoteç of mouge click 8
O Tmplement MoUse
(1eote
ListeneY i
Oclos thot imple nents NOU6eliston e ,
oUeide mousecliCked ethod
IrGide this method
you con get the coordinoteg
Get co0Tdinotes;
Use qet x() getu) fiom the mouGeCuont pO10metey
aAddliGtere
(iSteney

OStees to AegisteY Pos oU6e Cuen t68


OcIea C Component -
Choo se the cwant
toCeg -0 T8utton ,IPane).
2) Implement Listney:
C1eote aclo6 tho t implment Mouse.

Listen ey oY MOuseotion Stone

c100t
Instontiate o0 l;stener Clo 5.
Pegistey the Listeney -
OSe the addm oUSe ListoneYC or MOUS eNotion

Lisenn( method on the (omo onent.

P2
AdvancedJava Programmning (2251 7)

2Not all COmponent


**w**************k.s
gen eO te Nouseuent.

XII. Exercise
Write a program to change the background color of Applet when User performs
events using Mouse
2. Write a program to count the number of clicks performned by the user in a Frame
window
1 Write a program to demonstrate the use of mouseDragged and mouseMoved
method of MouseMotionListener
(Space for answer)

ninpovt jov0 0pplet.Applet


impOrt jova Owt ****************e
ww***

impot javo -awt-eUent. ********.k*k**k

PUblic clas6 ColoyChonggApplet Oxtend

Applet implment5 MoUse LigteneY

Public boidinitl )

addMou6e listonerC this)j

Public 00idoUS e CliCk ed (HoUGe Cuent e)

SetBotk g10Ud(ne olor((int) (Math.iond Om


OxLO0 GO0c )));

ePoint(0j

Public 001d PaintCG1aphic6 9)

9-d10w Stiing ("click to chonge colo1|" ,20, 7o);

PubliC yoid mouspPye ssed(ouseuente)


e)
PubliC u0id mousele0sedC HOUsefun

61
Maharashtra state Board of Technical Education
Programming(225 17)
Advanced Java i60cntered CHouS
m ou6
PubliC woid mouG eCxitedC

PUbiC .* * * * *
Reading
Further
Suggestions for
1. https://www.javatpoint.com/java-mouselistener
References/ Herbert Schildt
XIV,
complete reference Java 2 by
2. The
Assessment Scheme
XV, Performance Indicators Weightage
70%
Marks)
Process related (35 30%
Logic formation 30%
Debugging ability 10%
2.
Follow ethical practices
30%
3. Marks)
Product related (15
10%
Expected output 10%
4.
Timely Submission
5. 10%
questions
6. Answer to sample 100%
Total(50 Marks)

Team Members
List ofStudents /

1.

2.
3.

Dated signature of
Marks Obtained Teacher

Process Product Total(50)


Related(35) Related(15)

Maharashtra state Board of Technical Education


dvanced Java Programming (225 17)

fm pot jovax Soing.j


ioport
publiC cIlas6 cickroUteY ex{ends Jfvome implement
MoUSeisteney

piuote int (OUnt Oj


pYiUOte Jlobel tobol hew JLobl el(clicks O )
Scoing(onStonts -ce NTeAD)oton
Public chck(ounlet) o a o H

setrile("click counten))nedoh
setGi2eC3oo20)3
set OetoukClos eoperotion( @x\r- oN-CIOs)3

add NoUGe listeneCthi9)3ro h4ro 0

moUseclicked CNGuGefuent e)u

lobel. setText(click.ttCoUnt)yio8
s loo
3
public ooid m0use PiessedCouse Euente o
publiC o0id mouse leosed CHoU6e Cuont e)
pu blic 00id mouselxi(ed CHogGe Cuent )
publiC soid mouse fn teredcMouse uont )

public staric oid oin(sting () onq S)

ui5i61eCtiUe))
new CUcKCOGntoyC0. 6 et
gmpork åou0x-6oinoj Advan

inpor tiov-0wt-euent.
OUGeNo tiGh GxOmple extend
Ady public cass
NOUSeNotion listener 1.

PriOte NouseH otio o Cxomole

SettitlecOUSe Notien Exom


olo')jdo
setsie30o,200))
N-C
Set DetoutClose Operation (ExIT-G
CddCto benj
add ougeHotion istener( t h i S j 9

Public uoid moUse DraggedC ou6e ruert

(obel.6 et TexEC"O09ged at :("Ee. getx+",


IV
PUblic mouse oUedCNOUSe Cuent e)
V.

lobel.aeText (('oued atic egetYD")


VI
Public static 601d moin (string CI angs)

hew MoUse Gioh GxompieCD. se Uisible

Education
Maharashtra state Board of Technical
Advanced.Java Programning (2251 7)

Practical No. 12: Write a program to demonstrate the use of


JTextField and JPasswordField using Listener Interface.
Practical Significance:
Apassword is used to authenticate the user to gain the access to website application
or device. The TextField control is used to accept the input from uscr. An interface is
used to implement the methods as per the users reauirements and achieve the cot
of multiple inheritance in java.
Relevant Program Outcomes (POs)
. Basic knowledge: Apply knowledge of basic mathematics, sciences and
engineering to solve the computer group related problems.
Discipline knowledge: Apply Computer Programming knowledge to sove
computer group related problems.
Experiments and practice: Plan to perfornm experiments and practices to usethe
resultsto solve the computer group related problems.
Engineering tools: Apply relevant Computer programming / technologies and
tools with an understanding of the limitations.
e
Individual and Team work: Function effectively as aleader and team member in
diverse/multidisciplinary teams.
Communication: Communicate effectively in oral and written form.
Competency and Practical skills
The practical is expected to develop the following skills:
1. Able to develop an application using JTextField
2. Able to develop an application using JPasswordField

IV. Relevant Course Outcome(s)


Handle events of AWT and Swing Components
V Practical Outcome (PrOs)
JPasswordField using
Write a program to demonstrate the use of JTextField and
Listener Interface

VI.
Relevant Affective domain related Outcome(s)
1. Follow precautionary measures.
2. Follow naming conventions.
3. Follow ethical practices.

VIL. Minimum Theoretical Background


JPasswordField:
form of password
The JPasswordField allows the user to enter the input text in the
characters. It inherits the JTextField class.

Maharashtra state Board of Technical Education 63


Advanced.Java Programming (225 17)

Program Cde: Teacher must assign a separate program statement to group of


3-4 students.
. Writea programn using JPasswordField to set the password character as # instead of *

Public clas9 Pa9s00d Cield GKomple


public 64oiC oid moinC Stiing () dig)
(rompl
JFsome Pomee new rEa dmo1!Poss oo1d fleld
JPos 6001d Field posso 01 dield s new JPoss oo1 dFipldCj
pOS6 o01dPield. 6techochon(t)
Prome add(neo TlobelC "nten PasS00n0 "))
Prome-add Cpas5 w01dF (eld)j
fiome - 6e t\oyout(new Plou loy out)
Fame-se [email protected](lose)j
Rsome-Get Si2e( 30011 oo)3
Prome.ser DisibleCtrue);

XI. Result (Output of Code):

fnter passcoOTg!

XIL. Practical Related Questions


Note: Below given are few sample questions for reference. Teacher must design
more such questions so as to ensure the achievement of identified C0.
1. Write the use of setEchoChar() method with suitable example.
2. Write the advantages of using JPasswordField over JTextField
3. Which component can be used to accept the multiline input from user.
(Space for answer)
D>The 5echoch o(choY C) method in JPOsSo01 dFie
.....

i5 USed
*******s*******

Maharashtra state Board of Technical Education 65


Advanced Java Programming (22517)
examplel8- impoit Jovax.6oing.j
w*****s***w

Public Stoti yoid


mgin(8ingJ avgs)
wew*****we*
*********************iiek****.*t*****
kew***t****..
o01 Pi *******.*.
Pield ofsnew sPOsS
PP-SeLCchoc hOTC))
pi"fn tey
GhowonfiY mDiglognUl
v*w******

Joptioh Pone. www****s******

Poac CoOYdoptiGn. G<- CA

2) Aduontages

Input Hondlin q
3Cho 10c tey contyol
DefauiE Behavio

input Paom
accept
applicotion
**********
o Jaua ..............

J1ext Aipd

XIII. Exercise
to demonstrate the use of nser
1. Write a program using JPasswordField and JTextField
authentication
the addition of two numbers.
2. Write a program using JTextField to perform if the length is
3. Write a program using JPasswordField to accept password from user and length must ba
less than6 characters then error message should be displayed *Password
>6 characters"
(Space for Answer)

J i m port i ovay-Swing.
PUblic CO55 Vse YAuth

PobliC stotic oid moi n(sbing() an gs)

Fsomez new JQme("V6er Auth'


J TextPield Usey Pi eld neu) I TetCieid0o)j
66
Maharashtra state Board of Technical Education
AdvancedJava Programming (22517)

TPas5001 d ield ****

****
***
******ks.
pOssield :ne
********se
s******

*****

login Button.odd Acti on .isIenerle .******ise

stiing 9('U6ey" cdugt3(USey pipld gororl


************..
********ves***.
d"poss"-equadsC NPUw stiing(re stiing (ras
eld. get Pass001d0))7"Logn
k*********s
4ucr6sfull" :" Lnsolid
CYdenloi 1s.'';
*****

toption Pane -sho wNes60geD ialog(Ome , msgl)


******
Rsameodd (newS Ponel() f4 *****

addluGev field i addC ps stield)odd ( l0gin BUtko ))


J})5
Psame-SetSiel SO, lo0)/
***.***

Bomeset betouitC\OSe Ope 1o tion cIfoome-ExIT- ON. C1or cb


Psame. setbisib leCtue);

imporE ioU0x -S0ing.j


Public claSs Add tion

PubliC Stotic 0d main(tin g() a195)

Ifsame some new Ieom Add numbeis)j


JrertPIpld num tnew I7ext Pield Cs)) nom2s
new Text Piela (s) j
Jeutton ado otton new JBuHton C"Add")

a dd BUtton .add Action (Gstenoil e


ink 6Um -In tege patspnZntCnUm glevt))
+ Integ ey-eos 5eTntCruml- getTOv tC))j
......*.

J option Pone. Show NOSSOge DialogC#rome,

Maharashtra state Board of Technical Education 67


Advanced.Java Programmingg (225 17)

Practical No. 13:


Write a
Drooram to demonstrate the use of

addC nUm 2):


addCadd Button);
3)])j
POme. sesineC2
Psame. seteou IE Close
solo0)jce
opesolion(I1ome-CrIT-0tlo)

îmeort Sauo x.soingj


publi C class pOSs oO1dcheck

pu blíc tdtiC oid moin (Sting or g5)

TPass001d Pield possfieldnfJpoSG oool Pield(Io);


reutton submit Button ne JB0tton(" subm(t")

SubmitButtan-ado Actisn (isteneCes


string m9g -( passfield -get pasSoord) lengthe6)
?'pas5 COOT ust be>6 choicten s' passcoT d
atcep ted.'
Joption Pone -shou es oge Diolog( nul, mg))

SFsome taom- neu JPomelPassO91 check) 1


[email protected] JPonel(O
Java Programming
Advanced.
(22517)
Practical No. 14:
Write a program to demonstrate the use
Practical Significance: InetAddress class and its factory methods. of

Java provides support for


ofsocket
programming. communication betweenfor two or more computers by the way
TCP. Socket lets the userIt toprovides the classes both the protocols that is UDP and
sharethe
data/information in it.create a client server communication in the network and
II.
Relevant Progranm Outcomes (POs)
Basic
knowledge:
engineering Apply
to solve the knowledge of basic
Discipline mathematics, sciences and basic
computer group related problems.
knowlrelated
computer group edge:problems.
Apply Computer
Programmi ng knowledge to solve the
Experiments
results
and
to solve the practice: Plan to perform experiments and
computer group related problems. practices to use te
Engineering tools: Apply relevant Computer
tools with an understanding of the programming / technologies and
Individual and Team work: limitations.
Function effectively as a leader and team
. diverse/multidisciplinary
Communication:
teams. member in
Communicate effectively in oral and written form.
Competency and Practical skills
Todevelop a program using
InetAddress class
The practical is expected to develop
1. Able to use the factory the following skills:
methods InetAddress class
2. Able to write program using
of
different constructors of the InetAddress class.
IV. Relevant Course Outcome(s)
Develop java programs using networking components
V. Practical Outcome (PrOs)
Write a program to demonstrate the use of InetAddress class and its
factory methods
VI. Relevant Affective domain related Outcome(s)
1. Follow precautionary measures.
2. Follow naming conventions.
3. Follow ethical practices.
VIL. Minimum Theoretical Background
The java's InetAddress encapsulates an IP address and used by the other networking
classes such as Socket, ServerSocket, URL, Datagram Socket, Datagram Packet. It is
used to represent both numerical and the domain name of the machine. InetAddress
can handle both IPV4 and IPV6.The InetAddress class has no visible constructors and
it uses the following factory methods.
1. static lnetAddress getLocalHost() throws UnknownHostException
2. static lnetAddress getByName(String hostName) throws UnknownHostException
3. static InetAddress[ getAlIByName(String hostName) throws
unknownHostException
Maharashtra state Board of Technical Education 75
Advanced Java Programming (22517)

VIII. Resources required (Additional)


Nil

IX. Resources used (Additional)


Quantity Remarks (If any)
Sr. Name of BroadSpecification
No. Resource

2
program statement to group of
assign a separate
X. Program Code: Teacher must
3-4 students.

code and write the output


I. Execute the following
import java.io.*;
import java.net.*:
public class InetDemo

public static void main(Stringl] args)


try
InetAddress ip=InetAddress.getBy Name("localhost"):
System.out.println("Host Name: "tip.getHostName)):
System.out.printin("IP Address:"tip.getHostAddress():

catch(Exception e) {System.out.println(e):}

XI. Result (Output of Code):

Ip ddd1099: 127.0o1

XII. Practical Related Questions


Note: Below given are few sample questions for reference. Teacher must design
more such questions so as to ensure the achievement of identified CO.
1. Write any four differences between IPV4 and IPV6
2. Write the use of getBy Name() and getAIIByName) method.
3. Write the steps to assign IP address to your machine

76
Maharashtra state Board of Technical Education
AdvancedJava Programming
(22517)

(Space for answer)

,oe***** length
**********
32 bit6(4 byteg)
*e*******.**
(0Forma! 12g bít( IG by(es )
*****
space
0ecimol Hexod ecim al
(onfigU1ation
4-3 *******
bi|i0n
340
***
5ecuiy
Honual ov DH(P stoteloss oto (ontigu sotioh
A C109enotion IPsec optionol ID sec mondatny
Rouler5 con Bog menl e*****ecsbsee

only soUTCe

1tOD6 tho
(ontoing (ocallat zp inston(
Inet Ades6 ******.**

A aet AW Nome
Bynome- 0etemine
host giuen the host's a l the CP addye55

O setp6 to As6ig LP Add o6S

Detemine the CuNTent Net 001k LnterPocei


dentify the netole interfore (e-a, Chennet
wiPDyou Ganls to (ontiqun
..........

(20se syste m Com nands 8


")5e the Command ine tool6(iPcan Pig n
".......***...e...***....

Uhiy /linur G\ helsh on cindoos) to Chan g


the Ip adorOS

6)ceeculre Commnand in Jaua.


Run time-get Runtime().ex ecl ( oY
PioceS5 Bailder to 1un System co mmand
trom your
****........ .. ..........**
biogOm.

Maharashtra state Board of Technical Education 77


Advanced Java Programming (22517)
1. Develop a program using InetAddress classto retrieveIP address of computer
XIL. Exercise
user.
by the for
when hostname is entered(Space Answer)

fmport iovo. nel

Public clas6
11*vk*****************

ain(skiing) angg
public 6tdtic uoid n

5ting host J
(sys(em.in);
SCanneY. inpUt = n 5connPr
6y5em-out PintlhlCntpr host
........

host - in put nexlinej *****.

LotAd1e65 add1ese Inet Addr05


9et BNom e Chos-)j
addiesa
5ystem-out. pin tlnlTP odd ress:"+
get Host Adod1e85())j
no me i t
System. Gut-piinl n(lHO5
addes5 get(HostNO mec)j

(atch C unkno U Hostxceptioh eY)

********
6yotem. out.pin Hn(could not nohojk)

Maharashtra state Board of Technical Education 78


Advanced lava Programming (22517)
demonstrate the use of
Practical No, 15: Write approgramto class and its methods URL
Connection
and URL

PracticalSignificance:
The Uniform resource locator in java allows the user to access the particular file or
resource which might be stored on any local or remote machine. The URL specifies
the complete path by which user can access file. It contains protocol address, port
humber and location of the particular resource.

Relevant
Basic Program
knowledge:Outcomes
Apply (POs)
knowledge of basic mathematics, sciences and basic
engincering to solve the computer group related problems.
Computer Programming knowledge to solve
Discipline knowledge: Apply
computer group related problems. practices to use th.
Experiments and practice: Plan to perform experiments and
results to solve the computer group related problems. / technologies and
e
Engineering tools: Apply relevant Computer programming
tools with an understanding of the limitations.
and team member in
" Individual and Team work: Function effectively as a leader
diverse/multidisciplinary teams.
Communication: Communicate effectively in oral and written form.
III, Competency and Practical skills
To develop a program using URL and URLConnection class
The practical is expected to develop the following skills:
1. Able to identify different types of ports and protocols
class.
2. Able todevelop an application using URL and URLConnection
IV. Relevant Course Outcome(s)
Develop java programs using networking components
V Practical Outcome (PrOs)
class and its
Write a program to demonstrate the use of URL and URLConnection
methods
VI. Relevant Affective domain related Outcome(s)
1. Follow precautionary measures.
2. Follow naming conventions.
3. Follow ethical practices.
VIL. Minimum Theoretical Background
The URIL provides easy to understand format to uniquely identify or address
information on the intemet. URLs are ample; every browser uses them to identify
information on the Web. URL class provides a simple, concise API to access
information across the Internet using URLs.
URLConnection is a class which is used to access the attributes of remote resource.
Once we made a connection to the remote resource, we are ready to use
URLConnection to check the properties of remote object before actually transporting
it locally.

Maharashtra state Board of Technical Education 80


Advanced Java Programming (22517)
println("Host: "+ hp.get Host()):
System.out,println("File:"
System.out. +hp.getFile():
System.out,println("Ext:"+hp.toExternalForm0):

XI. Result (Output of Code):


Ple**
10ss*****w*v*w*****k*****
Poin.Com
w*******
HOS ww***it*********i*******
poin.ComjaNOx
w*****i****.
*.******

Teacher must design


XII. Practical Related Questions
sample questions for reference.
Note: Below given are ensure the achievement of identified CO.
few
so as to class.
more such questionsopen Connection )method of URLConnection
I. Write the use of exception that can be thrown by URL cass
Z. Write the name of which URL class is defined.
3. Name the package in
(Space for answer)

open(onrectionl) method
J S The speciied oRL and
OpehG he (onnpctioh
thot 1epe sen t a
URL cohneCtion insto nce
1emote objects
(orneCtion to th e
*********.

bu the URL
reCt
be no ted (-hot a ORC Coh
******************.

- T hould
GY nstonce does ngt: e5 toblig h
....***.*....*

(he actu
o n the (Yeotign

2 j O v d -net.uRl

3 ) a l PomnedorlCx(eplion

Maharashtra state Board of Technical Education 82


Java
tdamccd.
Programming (22517)

Exercise
1. Write a program using URL class to retrieve the host. protocol. port and file of
URL http://www.msbte.org in
Write a
2. program using URI and
content type, content length URLConnection
information of any
class to retrieve the date.
(Space for Answer) entered URL
)fropovt -)aa-nel
Public
s*****

\a66 ORL.
publiC sto tiC
*******.
Demo
u0id moin
publiC 3Molto\od URLEyceptio (6tsing-0195 )

Atem.00t.Pintlh( p3otorol
******

t dg e
Iriedt)j
tem-0ut. pint)nC i Pont U-getpot (3) 1
S46tem- oat- prin }l h( tugeHilec);
U-get2e1))3
AuGtem-0ut. pTntnCEyiF +Uto f tenctionl)3

Maharashtra state Board of Technical Education 83


Ahancet
dJava Programming (22512)

Practical No. 16:


Write a
programandto implement
Server Socket
Socket Class. chat Server using
fmpont
tmpoxt
jOVa-io
irpot -0t-Dota

Public Static

Ev Cepion boi0noin (otiing O195 ())

int chj
ORL phaso. cove)
e
ConneCtIoh hondi@-(onvoction handle
Gpen (onnection traa dote inoj
int le ng th
clato,i
no-handle-comnenctioh got Dota;
Su5tem-0ut- Println(patthew oatecode ,i04
AuAtem.out Pint\nCCantexk typeihand Ie
ConnCtion get

leng th length
-Connection.getrontextlenglhl)y
Suslerm-oUt-rintlhCcon texk length:' lenyth))
Adanced Java
Programming (2251 7)
1

PracticalINo. 18: Write a


program to insert and retrieve data from
database using JDBC.
Practical Significance:
ODBCisn't appropriate for direct use from the
usesa Cinterface. The JDBC API was modeledJavaafter ODBC, but,language
because JDBC is ita
because
programming
Java API. it offers a natural Java interface for working with SQL. JDBC is needed to
providea "pureJava" solution for application
Relevant Program Outcomes (POs)
development.
Basie knowledge: Apply
knowledge of basic mathematics, sciences and basic
oineering to solve the computer
Discipline knowledge: Apply group related problems.
computer group related problems. Computer Programming knowledge to solve the
Experiments and practice: Plan to
perform Cxperiments and practices to use the
results to solve the computer group related
Engincering tools: Apply relevant problems.
Computer programming / technologies and
tools with an understanding of the limitations,
Individual and Team work: Function effectively as a leader andteam
diverse/multidisciplinary teams. member in
Communication: Communicate effectively in oral and written form.
Competency and Practical skills
To develop Dynamic web Application
The practical is expected to develop the following skills:
1 Able to apply the JDBC to create table, and insert data in a table.
Able to demonstrate the use of various JDBC driver and tier application .

IV. Relevant Course Outcome(s)


Develop programs using JDBC

V.
Practical Outcome (PrOs)
Write a program toinsert and retrieve data from database using JDBC
VI. Relevant Affective domain related Outcome(s)
1. Follow precautionary measures.
2. Follow naming conventions.
3. Follow ethical practices.
VIL. Minimum Theoretical Background
JDBC APl enables the application to interact with the different types of databases.
It is possible to publish vital information from a remote database on a webpage using the Java
applet. JDBC is a low level API is used to invoke or call SQL command directly. The
required SQL statements are passed as a 'string' to java methods.

Maharashtra state Board of Technical Education 95


AdvancedJava Programming (22517)

Program Code:
3-4 students. Teacher must assign a
separate programn statement to group of
, Write a Program to create a
Student table. Student Table in database and insert a record in a
2. Write the output of
3.
following code
Create DSN Named as
1This program uses typesMSBTE using
I driver JDBCAdministrative lool from control Panel.
ODBC bridgc.
import java.sql":
class JdbcDemo
public static void main (String ares|])
try

DriverManager.registerDriver(new sun.jdbc.odbe.JdbcOdbcDriver):
System.out. println(" Driver loaded");:
String url-"jdbe:odbc:MSBTE",
Connection cn DriverManager.getConnection(url):
System.out.println("Connection to the database created"):
Statement st cn.createStatement):
String str= "select* from student"':
Resul
StringtStext
etrs=st"":.executeQuery(str):
System.out.println("Roll Number it Name"):
while(rs.next()
Dii0er log ded
text texttrs.getInt(1 )+"\t"rs. getString(2)+"n": connttion to the
databsecieo ted
System.out.print(text): Roli umbe nome
St.close):
cn.close): -
John Ooe
Jdne 6 mith
catch (SQLExccpt.ion s)
utPU .
{System.ou.printin("sql error"):

J import savg.5q1. Connectionj


ím port sdud.6q1.D1ivey onagenj
import jauo.sql .SoLCrecptiohj
import iova.sq!.60l.6totement
public clas5 short 50dents DB

Maharashtra state Board of Technical Education 97


Advanced Java Programming (22517)
angs)
Public stotic Uoidoin(sting C3
Shing hoßl;390l you.
obUT15 "idbcimysql://lorgl
Sting USeyouy-06ex no mPj
Sting pass t youY- Pds5 001 O"j

y(connection
Conn: 0hiuey Mono gey-getconnec tion
Cdbuah Useass)j
6taemen tl0)
Sto tement atmk sconn .caeate

Stml.execuLe Upda Le("CR EAre TABLE tf NoT Ex1S r5


5TudentSCid Nt AUTo.INC RC NENT P RTNAR Y KEy)
nome VARCHRC1o0)) 0ge rvty,
Stmt.eerOteUp date(" |NSEAT INTO tUdent (nome; 0ge)
UALUESCIoh n Doe'o) nj
S9Stem-Out-printlh(" Tobl0 C1e ted o)efovd n5etod.1

(otchC50L Cxception e)
e-pintStackra arpl);

XL. (Output of Code):

Table
and YeCOrO in5ete.
.......

XIL. Practical Related Questions


Note: Below given are few sanple questions for reference. Teacher must design
more such questions soas to ensure the achievement of identified CO.
1. List the advantages of JDBC over ODBC?
2. Write the Use of Class. forName()?
3. Write the steps to establish DSN oriented connection and DSNLess connection.

(Space for answer)

Maharashtra state Board of Technical Education


Advanced| Java Programming:(225 17)

0 plolovm Indend on re
********s**

IOUa Integotion
6impilified Cx¢ep tion
*******************.
Hondling

i ’ The clas5. oYNo mermetbod


cnomicgily \oad the TDAC diver clg5 into
he memony.e
a) Osteps oF0SN-01ienLed
******.******. Connection
OCeo Le a oota ounCe NamecDs
***************..*...
Lood ToBc -ODBC Gridge Dsiuer(pepico te)
****.....

cotoblishConneCtion DSing DsN


Ostp oP DsN - |e8s (obnction
........

Olood {he Appiate UOBC DiveY


2Estdblish (onnectíon wíth cornrioh uRL

XII. Exercise
1. Develop a program to create employee table in database having two columns
"emp id" and emp name",
2. Develop a program to display the name and roll no of students from "student
table" having percentage > 70.
Maharashtra state Board of Technical Education 99
Atvced Jevn PrormnE 22817)
(SpaceforAnewer)

Tabl@
ployee
fmpostClasscspoLoCro
PUblic ags)
moin(sing)
uoid
PUblic 2iatic
Jdbctmysal:/lletolhO5t3306J

y00Y dbuy
SLhing da4g bose_oomej

e*****
c.aeko nectioN
anOgeT.ge
03i0er
tgcconDRtion conD: 5t0Benont(1)1
e******ee
(1e0te
(onn.
S+Oement gtm
NoT
("CRCATe TABLE
5tmt-exeCute Upda Lo PRIMARy *******

(emp_id tNT ****....


ss****ee
*****eees.:
employee
RCHAR (1O0)) " j
empnom@ uA P1inHn("Cmpl oyee tOble c1eOtod-
5y stem.out

CotCh (50LCNCeptioh )

e. prin tstacroce5

10
Maharashtra state Board of Technical Education

You might also like