+ All Categories
Home > Documents > Wt Record Part 3

Wt Record Part 3

Date post: 14-Apr-2018
Category:
Upload: deepa-arun
View: 218 times
Download: 0 times
Share this document with a friend
62
Ex.No:6.a Date: IMPLEMENTATION OF JAVA DATABASE CONNECTIVITY (JDBC) AIM: To connect the database using jdbc connectivity in java. ALGORITHM: Step 1: Start the program. Step2 : Write the source code for connectivity. Step 3: Using MS-Access, save the database. Step 4: connect the database using ODBC Source connection. Step 5: Add the database name in ODBC data source administrator. Step 6: Add the table name to connection. Step 7: Compile the program and execute it. Step 8:Stop the program.
Transcript
Page 1: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 1/62

Ex.No:6.a

Date:

IMPLEMENTATION OF JAVA DATABASE CONNECTIVITY (JDBC)

AIM:

To connect the database using jdbc connectivity in java.

ALGORITHM:

Step 1: Start the program.

Step2 : Write the source code for connectivity.

Step 3: Using MS-Access, save the database.

Step 4: connect the database using ODBC Source connection.

Step 5: Add the database name in ODBC data source administrator.

Step 6: Add the table name to connection.

Step 7: Compile the program and execute it.

Step 8:Stop the program.

Page 2: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 2/62

PROGRAM:

import java.sql.*;

import java.io.*;

 public class jdbcdemo

{

 public static void main(String args[])

{

Connection c= null;

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

c=DriverManager.getConnection("jdbc:odbc:jdbcdemodb");

Statement stmt=c.createStatement();

ResultSet rs=stmt.executeQuery("select * from Employee");

System.out.println("name and password are");

while(rs.next())

{

System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3));

}

c.close();

}

catch(SQLException e1)

{

e1.printStackTrace();

}

catch(Exception e)

{

System.out.println("error"+e.getMessage());

}

}

}

Page 3: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 3/62

Ouptut:

Page 4: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 4/62

 

RESULT:

Thus the implementation of Java Database connectivity has been executed

successfully.

Page 5: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 5/62

Ex.No: 6b

Date :

IMPLEMENTATION OF SERVLET - JDBC DEMO PROGRAM

AIM:

To create a servlet with JDBC connectivity in java.

ALGORITHM:

Step 1:Start the program.

Step 2:Get the context text at Servlet at text html.

Step 3:Get the response from the user by entering the username field.

Step 4: Get the response from the user by entering the password field.

Step 5:If the username and password are correct, then the user is authenticated and can enter 

into web page.

Step 6:Execute the program in Internet Explorer.

Step 7 :Write the source code for connectivity.

Step 8:Using MS-Access, save the database.

Step 9:connect the database using ODBC Source connection.

Step 10: Add the database name in ODBC data source administrator.

Step 11:Add the table name to connection.

Step 12:Compile the program and execute it.

Step 13 :Stop the program.

Page 6: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 6/62

PROGRAM:

import javax.servlet.*;

import java.io.*;

import java.sql.*;

 public class servletdemojdbc implements Servlet

{

 public void init(ServletConfig c) throws ServletException

{

//super.init(c);

System.out.println("joint method");

}

 public void service(ServletRequest req,ServletResponse res)throws

ServletException,IOException

{

Connection c= null;

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");c=DriverManager.getConnection("jdbc:odbc:jdbcdemo");

Statement stmt=c.createStatement();

ResultSet rs=stmt.executeQuery("select * from Employee");

System.out.println("name and password are");

while(rs.next())

{

System.out.println(rs.getString(1)+"\t"+rs.getInt(2)+"\t"+rs.getDouble(3));}

c.close();

}

catch(SQLException e1)

{

e1.printStackTrace();

}

Page 7: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 7/62

catch(Exception e)

{

System.out.println("error"+e.getMessage());

}System.out.println("exec ");

}

 public String getServletInfo()

{

String author="raman";

String program="c";

System.out.println(author+"wrote"+program);

return null;

}

 public ServletConfig getServletConfig()

{

return null;

}

 public void destroy()

{

}

}

Page 8: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 8/62

Sample output: 

Page 9: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 9/62

 

RESULT:

Thus the program for database connectivity using jdbc has been created and executed

successfully.

Page 10: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 10/62

EX.No:7

Date:

SAMPLE WEB APPLICATION DEVELOPMENT IN THE OPEN SOURCE

ENVIRONMENT WITH DATABASE ACCESS

AIM: 

To create Sample web application development in the open source environment.

ALGORITHM:

Step1: start the program

Step2: Inside the asp definiton tag include the html contents

Step3: include the code for the database connectivity using the ado object

Step4: select all the datas form the student table

Step5: Traverse all the tuples in the table

Step6: Print the datas

Step7: close the connection

Step8: stop the program.

Page 11: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 11/62

PROGRAM:

access.asp file:

<% Option Explicit %>

<html>

<% DIM name

set con=Server.CreateObject("ADODB.Connection">

con.open "dsn=cse;"

set rs=Server.Createobject("ADODB.RecordSet")

set rs=con.Execute("select * from student where name="&name&")%>

<table border="," width="50"%>

<% while NOT rs.EOF %>

<tr><% for t=0 to 6 %>

<td><% Response.write(rs(i)) %>

<% NEXT %></td></tr>

<% Move Next wend %></table>

<%con.close%>

</html>

stuaccess.html file:

<html>

<form action="access.asp" method="post">

 Name<input type="text" name="Name"><br><br>

<input type="submit">

<input type="reset">

</form>

</html>

Page 12: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 12/62

Output: 

Page 13: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 13/62

 

RESULT :

Thus the Sample web application development in the open source environment has

 been executed successfully executed.

EX.No:8

Page 14: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 14/62

Date:

CREATION OF XML DOCUMENT FOR A SPECIFIC DOMAIN.

AIM:

To creation of XML document for a specific domain

ALGORITHM:

Step1:start the program

Step2:using Onclick(),validate the student details as entered.

Step3:In XML file,we use styles for structure the program as #PCDATA(datafield)

Step4:Using various HTML tags and attribute,we design the web page.

Step5:Using various XML attribute list and entity list to retrieve the information of student.

Step6:Using processing instructions which we required to describe the data.

Step7:Using “note.xml”as xmlid to connect with html file.Execute the program. 

Step8:Stop the program.

Page 15: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 15/62

Program

Student.html:

<HTML>

<HEAD>

<SCRIPT>

function prev_onclick()

{

std.previousPage()

}

function next_onclick()

{

std.nextPage()

}

</SCRIPT>

</HEAD>

<BODY>

<xml id="note" src="note.xml"></xml>

<table id="std" dataSrc="#note" datapagesize="1" border="1"><thead>

<tr><th>REGNO</th><th>NAME</th><th>COURSE</th><TH>SEM</th></tr>

</thead>

<tbody>

<tr><td><span datafld="REGNO"></span></td>

<td><span datafld="NAME"></span></td>

<td><span datafld="COURSE"></span></td>

<td><span datafld="SEM"></span></td>

</tr>

</tbody>

</table>

<INPUT TYPE="BUTTON" VALUE="NEXT" ONCLICK="next_onclick()">

<INPUT TYPE="BUTTON" VALUE="PREVIOUS" ONCLICK="prev_onclick()">

</BODY>

</HTML>

Page 16: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 16/62

 

note.xml:

<?xml version="1.0"?>

<note>

<STUDENT>

<REGNO>VMP49</REGNO>

<NAME>THANUJA.O</NAME>

<COURSE>M.E CSE</COURSE>

<SEM>II</SEM>

</STUDENT>

<STUDENT><REGNO>VMP52</REGNO>

<NAME>TAMILARASI</NAME>

<COURSE>M.E CSE</COURSE>

<SEM>II</SEM>

</STUDENT>

</note>

Page 17: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 17/62

 

Output :

Page 18: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 18/62

 

RESULT :

Thus the developing XML program has been executed successfully.

Page 19: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 19/62

EX. No: 9

Date :

WRITING DTD OR XML SCHEMA FOR THE DOMAIN SPECIFIC XML

DOCUMENT

AIM:

To write a program for DTD and XML schema for the domain specific XML

document.

ALGORITHM:

Step1:start the program

Step2:open an XML file as Letter.xml, to create detail of person using various xml attribute

list

Step3:using user defined tags, we can create details of person using name, pincode, address,

 ph.no, etc..

Step4:open DTD file as letter . dtd

Step5:using an external and internaldtd,we create elementlist as #PCDATA for retrieve the

datafield

Step6:using attribute declaration ,use to retrieve the datafield as more than one time

Step7:Execute the program

Page 20: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 20/62

Program: 

Letter.xml:

<?xml version="1.0"?>

<letter>

<contact type="sender">

<name>aaaa</name>

<address>dfdsgdsgdsfvg</address>

<city>chennai</city>

<state>tamilnadu</state>

<zip>600089</zip>

<phone>044-23456789</phone>

<flag gender="F"/>

</contact>

<contact type="receiver">

<name>bbbb</name>

<address1>dfdsgdsgdsfvg</address1>

<address2>fvgefgffdg</address2>

<city>chennai</city>

<state>tamilnadu</state>

<zip>600089</zip>

<phone>044-23456789</phone>

<flag gender="F"/>

</contact>

Page 21: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 21/62

<salutation>Dear Sir: </salutation>

<paragraph>It is our privillege .........</paragraph>

<closing>Sincerely</closing>

<signature>Ms.aaaaa</signature>

</letter>

Letter.dtd: 

<!element letter(contact+, salutation, paragraph+, closing, signature)>

<element contact(name, address1, address2, city, state, zip, phone, flag)>

<!attlist contacttype CDATA #implied>

<!element address1(#PCDATA)>

<!element address2(#PCDATA)>

<!element city(#PCDATA)>

<!element state(#PCDATA)>

<!element zip(#PCDATA)>

<!element phone(#PCDATA)>

<!element flag EMPTY>

<!attlist flag gender(M/F)"M">

<!element salutation(#pcdata)>

<!element closing (#pcdata)>

<!element paragraph (#pcdata)>

<!element signature (#pcdata)>

Page 22: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 22/62

output:

Page 23: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 23/62

 

RESULT:

Thus the program for writing DTD or XML schema for the domain specific XML

document has been successfully completed.

Page 24: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 24/62

Ex.No:10

Date:

PARSING AN XML DOCUMENT USING DOM AND SAX PARSERS.

AIM:

To Parsing an XML document using DOM and SAX Parsers.

ALGORITHM :

Using Dom:

Step1: Get a document builder using document builder factory and parse the xml file to create

a DOM object

Step 2: Get a list of employee elements from the DOM

Step3: For each employee element get the id, name, age and type. Create an employee value

object and add it to the list.

Step4: At the end iterate through the list and print the employees to verify we parsed it right.

Using Sax

Step1: Create a Sax parser and parse the xml

Step2: In the event handler create the employee object

Step3 : Print out the data

Page 25: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 25/62

PROGRAM:

employees.xml

< ? x m l

v e r s i o n = " 1 . 0 "

e n c o d i n g = " U T F - 8 " ? >  

< P e r s o n n e l >  

< E m p l o y e e

t y p e = " p e r m a n e n t " >  

< N a m e > S e a g u l l < / N a

m e >  

< I d > 3 6 7 4 < / I d >  

< A g e > 3 4 < / A g e >  

< / E m p l o y e e >  

< E m p l o y e e

t y p e = " c o n t r a c t " >  

< N a m e > R o b i n < / N a m e

>  

< I d > 3 6 7 5 < / I d >  

Page 26: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 26/62

< A g e > 2 5 < / A g e >  

< / E m p l o y e e >  

< E m p l o y e e

t y p e = " p e r m a n e n t " >  

< N a m e > C r o w < / N a m e >  

< I d > 3 6 7 6 < / I d >

< A g e > 2 8 < / A g e >

< / E m p l o y e e >  

< / P e r s o n n e l >

Using DOM  

D o m P a r s e r E x a m p l e . j

a v a

a) Getting a document builder 

 p r i v a t e v o i d

 p a r s e X m l F i l e ( ) {

/ / g e t t h e

f a c t o r y

Page 27: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 27/62

 

D o c u m e n t B u i l d e r F a

c t o r y d b f =

D o c u m e n t B u i l d e r F a c

t o r y . n e w I n s t a n c e ( )

;

t r y {

/ / U s i n g

f a c t o r y g e t a n

i n s t a n c e o f  

d o c u m e n t b u i l d e r  

D o c u m e n t B u i l d e r  

d b =

d b f . n e w D o c u m e n t B u

i l d e r ( ) ;

/ / p a r s e u s i n g

 b u i l d e r t o g e t D O M

Page 28: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 28/62

r e p r e s e n t a t i o n o f  

t h e X M L f i l e

d o m =

d b . p a r s e ( " e m p l o y e e

s . x m l " ) ;

} c a t c h ( P a r s e r C o n f  

i g u r a t i o n E x c e p t i o n

 p c e ) {

 p c e . p r i n t S t a c k T r a

c e ( ) ;

} c a t c h ( S A X E x c e p t i

o n s e ) {

s e . p r i n t S t a c k T r a c

e ( ) ;

Page 29: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 29/62

 

} c a t c h ( I O E x c e p t i o

n i o e ) {

i o e . p r i n t S t a c k T r a

c e ( ) ;

}

}  

 b) Get a list of employee elementsGet the rootElement from the DOM object.From the root element get all employee elements.Iterate through each employee element to load the data.

 p r i v a t e v o i d

 p a r s e D o c u m e n t ( ) {

/ / g e t t h e r o o t

e l e m e n t

E l e m e n t d o c E l e

=

d o m . g e t D o c u m e n t E l e

m e n t ( ) ;

Page 30: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 30/62

/ / g e t a n o d e l i s t

o f 

e l e m e n t s

 N o d e L i s t n l =

d o c E l e . g e t E l e m e n t s

B y T a g N a m e ( " E m p l o y

e e " ) ;

i f ( n l ! = n u l l & &

n l . g e t L e n g t h ( ) >

0 ) {

f o r ( i n t i = 0 ;

i <

n l . g e t L e n g t h ( ) ; i + +

) {

/ / g e t t h e

e m p l o y e e e l e m e n t

E l e m e n t e l =

( E l e m e n t ) n l . i t e m ( i

) ;

Page 31: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 31/62

 

/ / g e t t h e

E m p l o y e e o b j e c t

E m p l o y e e e =

g e t E m p l o y e e ( e l ) ;

/ / a d d i t t o

l i s t

m y E m p l s . a d d ( e ) ;

}

}

}  

c) Reading in data from each employee.

/ * *

* I t a k e a n

e m p l o y e e e l e m e n t

a n d r e a d t h e

v a l u e s i n , c r e a t e

Page 32: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 32/62

* a n E m p l o y e e

o b j e c t a n d r e t u r n

i t

* /

 p r i v a t e E m p l o y e e

g e t E m p l o y e e ( E l e m e n

t e m p E l ) {

/ / f o r e a c h

< e m p l o y e e > e l e m e n t

g e t t e x t o r i n t

v a l u e s o f  

/ / n a m e , i d , a g e

a n d n a m e

S t r i n g n a m e =

g e t T e x t V a l u e ( e m p E l

, " N a m e " ) ;

i n t i d =

g e t I n t V a l u e ( e m p E l ,

" I d " ) ;

Page 33: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 33/62

i n t a g e =

g e t I n t V a l u e ( e m p E l ,

" A g e " ) ;

S t r i n g t y p e =

e m p E l . g e t A t t r i b u t e

( " t y p e " ) ;

/ / C r e a t e a n e w

E m p l o y e e w i t h t h e

v a l u e r e a d f r o m

t h e x m l n o d e s

E m p l o y e e e =

n e w

E m p l o y e e ( n a m e , i d , a

g e , t y p e ) ;

r e t u r n e ;

}

/ * *

Page 34: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 34/62

* I t a k e a x m l

e l e m e n t a n d t h e

t a g n a m e , l o o k f o r  

t h e t a g a n d g e t

* t h e t e x t

c o n t e n t

* i . e f o r  

< e m p l o y e e > < n a m e > J

o h n < / n a m e > < / e m p l o

y e e > x m l s n i p p e t

i f 

* t h e E l e m e n t

 p o i n t s t o e m p l o y e e

n o d e a n d t a g N a m e

i s ' n a m e ' I w i l l

r e t u r n J o h n

* /

Page 35: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 35/62

p r i v a t e S t r i n g

g e t T e x t V a l u e ( E l e m e

n t e l e , S t r i n g

t a g N a m e ) {

S t r i n g t e x t V a l =

n u l l ;

 N o d e L i s t n l =

e l e . g e t E l e m e n t s B y T

a g N a m e ( t a g N a m e ) ;

i f ( n l ! = n u l l & &

n l . g e t L e n g t h ( ) >

0 ) {

E l e m e n t e l =

( E l e m e n t ) n l . i t e m ( 0

) ;

t e x t V a l =

e l . g e t F i r s t C h i l d ( ) .

g e t N o d e V a l u e ( ) ;

}

Page 36: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 36/62

r e t u r n t e x t V a l ;

}

/ * *

* C a l l s

g e t T e x t V a l u e a n d

r e t u r n s a i n t v a l u e

* /

 p r i v a t e i n t

g e t I n t V a l u e ( E l e m e n

t e l e , S t r i n g

t a g N a m e ) {

/ / i n p r o d u c t i o n

a p p l i c a t i o n y o u

w o u l d c a t c h t h e

e x c e p t i o n

r e t u r n

I n t e g e r . p a r s e I n t ( g

Page 37: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 37/62

e t T e x t V a l u e ( e l e , t a

g N a m e ) ) ;

}  

d) Iterating and printing.

 p r i v a t e v o i d

 p r i n t D a t a ( ) {

S y s t e m . o u t . p r i n t l

n ( " N o o f E m p l o y e e s

' " +

m y E m p l s . s i z e ( ) +

" ' . " ) ;

I t e r a t o r i t =

m y E m p l s . i t e r a t o r ( )

;

w h i l e ( i t . h a s N e x t (

) ) {

Page 38: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 38/62

 

S y s t e m . o u t . p r i n t l

n ( i t . n e x t ( ) . t o S t r i n

g ( ) ) ;

}

}

U s i n g S a x :

S A X P a r s e r E x a m p l e . j

a v a

a) Create a Sax Parser and parse the xml

 p r i v a t e v o i d

 p a r s e D o c u m e n t ( ) {

/ / g e t a f a c t o r y

S A X P a r s e r F a c t o r y

s p f =

S A X P a r s e r F a c t o r y . n

e w I n s t a n c e ( ) ;

Page 39: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 39/62

t r y {

/ / g e t a n e w

i n s t a n c e o f p a r s e r  

S A X P a r s e r s p =

s p f . n e w S A X P a r s e r ( )

;

/ / p a r s e t h e

f i l e a n d a l s o

r e g i s t e r t h i s c l a s s

f o r c a l l b a c k s

s p . p a r s e ( " e m p l o y e

e s . x m l " , t h i s ) ;

} c a t c h ( S A X E x c e p t i

o n s e ) {

Page 40: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 40/62

 

s e . p r i n t S t a c k T r a c

e ( ) ;

} c a t c h ( P a r s e r C o n f  

i g u r a t i o n E x c e p t i o n

 p c e ) {

 p c e . p r i n t S t a c k T r a

c e ( ) ;

} c a t c h

( I O E x c e p t i o n i e ) {

i e . p r i n t S t a c k T r a c

e ( ) ; } }

 b) In the event handlers create the Employee object and call the corresponding setter methods.

/ / E v e n t H a n d l e r s

 p u b l i c v o i d

s t a r t E l e m e n t ( S t r i n

Page 41: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 41/62

g u r i , S t r i n g

l o c a l N a m e , S t r i n g

q N a m e ,

A t t r i b u t e s

a t t r i b u t e s ) t h r o w s

S A X E x c e p t i o n {

/ / r e s e t

t e m p V a l = " " ;

i f ( q N a m e . e q u a l s I g

n o r e C a s e ( " E m p l o y e e

" ) ) {

/ / c r e a t e a n e w

i n s t a n c e o f  

e m p l o y e e

t e m p E m p = n e w

E m p l o y e e ( ) ;

t e m p E m p . s e t T y p e ( a

Page 42: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 42/62

t t r i b u t e s . g e t V a l u e

( " t y p e " ) ) ;

}

}

 p u b l i c v o i d

c h a r a c t e r s ( c h a r [ ]

c h , i n t s t a r t , i n t

l e n g t h ) t h r o w s

S A X E x c e p t i o n {

t e m p V a l = n e w

S t r i n g ( c h , s t a r t , l e n

g t h ) ;

}

 p u b l i c v o i d

e n d E l e m e n t ( S t r i n g

u r i , S t r i n g

l o c a l N a m e ,

Page 43: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 43/62

S t r i n g q N a m e )

t h r o w s

S A X E x c e p t i o n {

i f ( q N a m e . e q u a l s I g

n o r e C a s e ( " E m p l o y e e

" ) ) {

/ / a d d i t t o

t h e l i s t

m y E m p l s . a d d ( t e m p

E m p ) ;

} e l s e i f  

( q N a m e . e q u a l s I g n o r  

e C a s e ( " N a m e " ) ) {

t e m p E m p . s e t N a m e (

t e m p V a l ) ;

Page 44: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 44/62

} e l s e i f  

( q N a m e . e q u a l s I g n o r  

e C a s e ( " I d " ) ) {

t e m p E m p . s e t I d ( I n t

e g e r . p a r s e I n t ( t e m p

V a l ) ) ;

} e l s e i f  

( q N a m e . e q u a l s I g n o r  

e C a s e ( " A g e " ) ) {

t e m p E m p . s e t A g e ( I n

t e g e r . p a r s e I n t ( t e m

 p V a l ) ) ;

}

}

c) Iterating and printing.

 p r i v a t e v o i d

 p r i n t D a t a ( ) {

Page 45: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 45/62

 

S y s t e m . o u t . p r i n t l

n ( " N o o f E m p l o y e e s

' " +

m y E m p l s . s i z e ( ) +

" ' . " ) ;

I t e r a t o r i t =

m y E m p l s . i t e r a t o r ( )

;

w h i l e ( i t . h a s N e x t (

) ) {

S y s t e m . o u t . p r i n t l

n ( i t . n e x t ( ) . t o S t r i n

g ( ) ) ;

} }

Page 46: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 46/62

O U T P U T :

E m p l o y e e D e t a i l s -

 N a m e : S e a g u l l ,

T y p e : p e r m a n e n t ,

I d : 3 6 7 4 , A g e : 3 4 .

E m p l o y e e D e t a i l s -

 N a m e : R o b i n ,

T y p e : c o n t r a c t ,

I d : 3 6 7 5 , A g e : 2 5 .

E m p l o y e e D e t a i l s -

 N a m e : C r o w ,

T y p e : p e r m a n e n t ,

I d : 3 6 7 6 , A g e : 2 8 .

Page 47: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 47/62

 

Page 48: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 48/62

 

RESULT:

Thus the Parsing an XML document using DOM and SAX Parsers is been done and

executed successfully.

Ex.No:

Date:

CREATION OF WEB APPLICATION USING PHP

AIM:

To create a calculator web appliction using php.

ALGORITHM :

Step1 : Start the program

Step2 : Create a php web page calc.php

Step3: Using form and input type tag create various buttons, textbox, radio button etc.

Step4: calcute the output for various option

Step5: using post method display the result in next page.

Step6: Stop the program.

Page 49: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 49/62

 

PROGRAM:

Calc.php:

<?php?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">

<head><title>Calculator</title>

</head><body>

<?php

// basic calculator programfunction showForm() {?>

All field are required, however, if you forget any, we will put a random number in for you.<br />

<table border="0"><form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"><tr>

<td>Number:</td><td><input type="text" maxlength="3" name="number" size="4" /></td>

</tr>

Page 50: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 50/62

<span id="square">

<tr><td>Another number:</td><td><input type="text" maxlength="4" name="number2" size="4" /></td>

</tr></span><tr>

<td valign="top">Operator:</td><td><input type="radio" name="opt" value="+" </>+<br />

<input type="radio" name="opt" value="-" />-<br /><input type="radio" name="opt" value="*" />*<br /><input type="radio" name="opt" value="/" />/<br /><input type="radio" name="opt" value="^2" />x<sup>2</sup><br /><input type="radio" name="opt" value="sqrt" />sqrt<br /><input type="radio" name="opt" value="^" />^<br />

</td></tr><tr>

<td>Rounding:</td><td><input type="text" name="rounding" value="4" size="4" maxlength="4" /></td><td><small>(Enter how many digits you would like to round to)</small></td>

</tr><tr>

<td><input type="submit" value="Calculate" name="submit" /></td></tr></form>

</table><?php

}if (empty($_POST['submit'])) {

showForm();} else {

$errors = array();$error = false;if (!is_numeric($_POST['number'])) {

(int)$_POST['number'] = rand(1,200);}if (empty($_POST['number'])) {

(int)$_POST['number'] = rand(1,200);}if (!is_numeric($_POST['number2'])) {

(int)$_POST['number2'] = rand(1,200);}if (empty($_POST['number2'])) {

(int)$_POST['number2'] = rand(1,200);}

if (empty($_POST['rounding'])) {$round = 0;

Page 51: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 51/62

}if (!isset($_POST['opt'])) {

$errors[] = "You must select an operation.";$error = true;

}

if (strpbrk($_POST['number'],"-") and strpbrk($_POST['number2'],"0.") and $_POST['opt']== "^") {

$errors[] = "You cannot raise a negative number to a decimal, this is impossible. <ahref=\"http://hudzilla.org/phpwiki/index.php?title=Other_mathematical_conversion_functions\">Why?</a>";

$error = true;}

if ($error != false) {echo "We found these errors:";

echo "<ul>";foreach ($errors as $e) {

echo "<li>$e</li>";}echo "</ul>";

} else {switch ($_POST['opt']) {

case "+":$result = (int)strip_tags($_POST['number']) + (int)strip_tags($_POST['number2']);echo "The answer to " . (int)strip_tags($_POST['number']) . " $_POST[opt] " .

(int)strip_tags($_POST['number2']) . " is $result."; break;

case "-";$result = (int)strip_tags($_POST['number']) - (int)strip_tags($_POST['number2']);echo "The answer to " . (int)strip_tags($_POST['number']) . " $_POST[opt] " .

(int)strip_tags($_POST['number2']) . " is $result."; break;

case "*";$result = (int)strip_tags($_POST['number']) * (int)strip_tags($_POST['number2']);echo "The answer to " . (int)strip_tags($_POST['number']) . " $_POST[opt] " .

(int)$_POST['number2'] . " is $result."; break;case "/";

$result = (int)strip_tags($_POST['number']) / (int)strip_tags($_POST['number2']);$a = ceil($result);

echo "<br />";echo "<hr />";echo "<h2>Rounding</h2>";echo "$result rounded up is $a";echo "<br />";$b = floor($result);

echo "$result rounded down is $b";echo "<br />";

Page 52: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 52/62

$h = round($result,(int)$_POST['rounding']);echo "$result rounded to $_POST[rounding] digits is " . $h;

 break;case "^2":

$result = (int)strip_tags($_POST['number']) * (int)strip_tags($_POST['number2']);

$a = (int)$_POST['number2'] * (int)$_POST['number2'];echo "The answer to " . (int)$_POST['number'] . "<sup>2</sup> is " . $result;echo "<br />";echo "The answer to " . (int)$_POST['number2'] . "<sup>2</sup> is " . $a;

 break;case "sqrt":

$result = (int)strip_tags(sqrt($_POST['number']));$sqrt2 = (int)strip_tags(sqrt($_POST['number2']));echo "The square root of " . (int)strip_tags($_POST['number']) . " is " . $result;

echo "<br />";echo "The square root of " . (int)strip_tags($_POST['number2']) . " is " . $sqrt2;

echo "<br />";echo "The square root of " . (int)strip_tags($_POST['number']) . " rounded to " .

strip_tags($_POST[rounding]) . " digits is " . round($result,(int)$_POST['rounding']);echo "<br />";echo "The square root of " . (int)strip_tags($_POST['number2']) . " rounded to " .

strip_tags($_POST[rounding]) . " digits is " .round($sqrt2,(int)strip_tags($_POST['rounding']));

 break;case "^":

$result = (int)strip_tags(pow($_POST['number'],$_POST['number2']));$pow2 = (int)strip_tags(pow($_POST['number2'],$_POST['number']));echo (int)$_POST['number'] . "<sup>" . strip_tags($_POST[number2]) . "</sup> is

" . $result;echo "<br />";echo (int)$_POST['number2'] . "<sup>" . strip_tags($_POST[number]) . "</sup>

is " . $pow2; break;

}

}}

echo "<br />";?><a href="calc.php">Go Back</a>

</body></html>

Page 53: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 53/62

 

OUTPUT:

Page 54: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 54/62

 

Page 55: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 55/62

 

Page 56: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 56/62

 

Result: 

Thus the calculator web appliction using php is been developed succesfully.

Page 57: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 57/62

Ex.No:

Date:

CREATION OF WEB APPLICATION USING PHP

AIM:

To create a calculator web appliction using php.

ALGORITHM :

Step1: Start the program

Step2: Create a php web page contact.php

Step3: Using form and input type tag create various buttons, textbox, radio

 button etc.

Step4: Get the necessary field from the user.

Step5: Using post method display the result in next page.

Step6: Stop the program.

Page 58: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 58/62

PROGRAM:

Contact.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>Web and Crafts</title>

<meta name="keywords" content="" />

<meta name="description" content="" />

<link href="style.css" rel="stylesheet" type="text/css" media="screen" />

</head>

<body><!-- #header-wrapper -->

<?php

$name = $_POST['name'];

$address = $_POST['address'];

$city = $_POST['city'];

$zip = $_POST['zip'];

$phonenumber = $_POST['phonenumber'];

$email = $_POST['email'];

$message = $_POST['message'];$error=0;

if (isset($_POST['submit'])) {

if (eregi('http:', $notes)) {

die ("Do NOT try that! ! ");

}

if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))

{

echo "<h2>Use Back - Enter valid e-mail</h2>\n";

$badinput = "<h2>Feedback was NOT submitted</h2>\n";

echo $badinput;

$error=1;

}

if(empty($name) || empty($phonenumber) || empty($email ) || empty($message)) {

echo "<h2>Use Back - fill in all required fields

</h2>\n"; $error=1; }

if($error!=1){

$todayis = date("l, F j, Y, g:i a") ; $attn = $subject ;

$subject = "mail from $email";$message = stripcslashes($message);

Page 59: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 59/62

$mailmessage = " $todayis [EST]

\n Subject: $subject \n Message: $message \n From:

$name ($email)\n City: $city\n Pin/Zip code: $zip\n PhoneNo:

$phonenumber\n

"; $from ="From: $email \r\n";mail("[email protected]" ,$subject,

$mailmessage,$from);

echo "Thank You :";

echo "$name(";

echo "$email )";

echo "for your interest in our services. We will contact

you soon <br>";

}

else

{

echo "Use Back and Fill all required fields !!";

}

}

else

{

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"

enctype="multipart/form-data" id="form1">

<table cellspacing="0" cellpadding="2" width="100%" border="0" class="text_main"><tr>

<td align="right" valign="center"><strong><font

color="#ff0000">*</font>&nbsp;Name : </strong></td>

<td align="left" valign="center"><input

style="WIDTH: 207px; HEIGHT: 22px" size="26" name="name" /></td>

</tr>

<tr>

<td align="right" valign="center"><strong>Address :</strong></td>

<td align="left" valign="center"><textarea style="WIDTH: 205px; HEIGHT: 80px"name="address" rows="6" cols="22"></textarea></td>

</tr>

<tr>

<td align="right" valign="center"><strong>City :</strong></td>

<td align="left" valign="center"><input

style="WIDTH: 205px; HEIGHT: 22px" size="26" name="city" /></td>

</tr>

<tr>

<td align="right" valign="center"><strong><font

color="#ff0000">*</font>&nbsp;Phone No :</strong></td>

<td align="left" valign="center"><input

Page 60: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 60/62

style="WIDTH: 168px; HEIGHT: 22px" size="21" name="phonenumber" /></td>

</tr>

<tr>

<td align="right" valign="center"><strong><font

color="#ff0000">*</font>&nbsp;Email :</strong></td><td align="left" valign="center"><input

style="WIDTH: 207px; HEIGHT: 22px" size="26" name="email" /></td>

</tr>

<tr>

<td align="right" valign="center"><strong><font

color="#ff0000">*</font>&nbsp;Your Message :</strong></td>

<td align="left" valign="center"><textarea style="WIDTH: 346px; HEIGHT: 158px"

name="message" rows="8" cols="37"></textarea></td>

</tr>

<tr>

<td valign="center" align="right"></td>

<td valign="center" align="left"><input type="submit" value="Send" name="submit"

/>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type="reset" value="Clear" name="reset" /></td>

</tr>

<tr>

<td valign="center" align="right"></td>

<td valign="center" align="left" height="15"></td>

</tr>

<tr>

<td align="right" valign="center"></td>

<td align="left" valign="center">Fields

marked <font color="#ff0000">*</font> are

mandatory</td>

</tr>

</table></form>

<?php

}

?>

</body>

</html>

Page 61: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 61/62

Page 62: Wt Record Part 3

7/30/2019 Wt Record Part 3

http://slidepdf.com/reader/full/wt-record-part-3 62/62

 

RESULT:

Thus the Php application has been developed and executed successfully.


Recommended