WPS RECORD PROGRAMS

38
WPSLAB PROGRAM:1 PROGRAM USING BASIC HTML TAGS  <!--USING BASIC HTML TAGS-------> <html> <head> <title>Basic html tags</title> </head> <body > <font color="brown" font face="arial helvetica "> <h1 align="center" ><u>!!WELCO ME!!</u></h1> <h2 align="center" >!!WELCOME! !</h2> <h3 align="center" >!!WELCOME! !</h3> <h4 align="center" >!!WELCOME! !</h4> <h5 align="center" >!!WELCOME!!</h5> <h6 align="center">!!WELCOME!!</h6> </font> <font color="green" size=10> <p>This is a <b><i>sample</i></b> of web page <br/>using basic html tags like<br/> </font> <font size=6 color="blu e"> <pre>heading s,font <sub>color s,types,sizes </sub>,ali gnments,subscri pts,pretag</pr e></p> </font> </body> </html> OUTPUT:  1

Transcript of WPS RECORD PROGRAMS

Page 1: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 1/38

WPSLAB

PROGRAM:1 PROGRAM USING BASIC HTML TAGS

 <!--USING BASIC HTML TAGS------->

<html><head>

<title>Basic html tags</title></head>

<body ><font color="brown" font face="arial helvetica "><h1 align="center"><u>!!WELCOME!!</u></h1><h2 align="center">!!WELCOME!!</h2><h3 align="center">!!WELCOME!!</h3><h4 align="center">!!WELCOME!!</h4>

<h5 align="center">!!WELCOME!!</h5><h6 align="center">!!WELCOME!!</h6>

</font><font color="green" size=10>

<p>This is a <b><i>sample</i></b> of web page <br/>using basichtml tags like<br/></font><font size=6 color="blue"><pre>headings,font <sub>colors,types,sizes</sub>,alignments,subscripts,pretag</pre></p>

</font></body></html>

OUTPUT:

 

1

Page 2: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 2/38

WPSLAB

PROGRAM:2 FORMATTING TAGS

<html>

<head>

<title>Formatting tags</title>

</head>

<body>

<h3 align="center">Formatting tags</h3>

<b>This text is bold</b><br/>

<big> This text is big </big><br/>

<i> This text is italic </i><br/>

<small> This text is small </small> </br>

This text contains <sub> subscript </sub> </br>

This text contains <sup> superscript </sup>

</body>

</html>

OUTPUT:

 

2

Page 3: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 3/38

WPSLAB

PROGRAM:3 PROGRAM USING LISTS

<html>

<head>

<title>Lists</title>

<style type=text/css>

p{color:teal}

</style>

</head>

<body>

<h1 align="center"><font color="purple"><u>USING

LISTS</u></font></h1>

<h2><font color="darkgreen"><b>THE SEVEN WONDERS OF

WORLD</b></font></h2>

<font color="brown">

<li><h3>Chichen Itza</h3>

<ul>

<li><h4><p>located in Yucatin,<i>MEXICO</i></p></h4></li>

<li>for image<a href="chichenitza.jpg">Click here</a></li>

</ul>

<li><h3>Taj Mahal</h3></li>

<ul>

<li><h4><p>located in Agra,<i>INDIA</i></p></h4></li>

<li>for image<a href="TAJ.jpg">Click here</a></li></ul>

<li><h3>The Great wall of China</h3></li>

<ul>

<li><h4><p>located in <i>CHINA</i></p></h4></li>

<li>for image<a href="greatwall.jpg">Click here</a></li>

</ul>

<li><h3>Colosseum</h3></li>

<ul>

<li><h4><p>located in Rome,<i>ITALY</i></p></h4></li><li>for image<a href="colosseum.jpg">Click here</a></li>

</ul>

<li><h3>Petra</h3></li>

<ul>

<li><h4><p>located in <i>JORDAN</i></p></h4></li>

<li>for image<a href="petra.jpg">Click here</a></li>

</ul>

<li><h3>Machu picchu</h3></li>

<ul>

<li><h4><p>located in cuzco,<i>PERU</i></p></h4></li>

3

Page 4: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 4/38

WPSLAB

<li>for image<a href="machupicchu.jpg">Click here</a></li>

</ul>

<li><h3>Christ The Redeemer</h3></li>

<ul>

<li><h4><p>located in Rio De Janerio,<i>BRAZIL</i></p></h4></li><li>for image<a href="christredeemer.jpg">Click here</a></li>

</ul>

</font>

</ol>

</body>

</html>

 

OUTPUT:

4

Page 5: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 5/38

WPSLAB

PROGRAM:4  LINKS

<html>

<head>

<title>LINKS </title>

</head>

<body>

<h1 align="center">Links</h1>

<ol>

<li><h2>Linking other html documents</h2></li>

<ul>

<li><a href="sample.html">Basic tags</a></li>

<li><a href="images.html">Displaying images</a></li>

</ul>

<li><h2>Linking images</h2></li>

<a href="sample.html">

<img src="petra.jpg" width=100 height=100>Petra</a><br/>

<a href="images.html">

<img src="Taj.jpg" width=100 height=100>TAJ</a>

</ol>

</body>

</html>

OUTPUT:

 

PROGRAM:5  PROGRAM TO ILLUSTRATE  IMAGES

5

Page 6: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 6/38

WPSLAB

<html>

<head>

<title>Images</title>

</head><body>

<h2 align="center"><i>Displaying images</i></h2>

<h3>1.TAJ</h3><center>

<img src="Taj.jpg" width=500 height=250></center>

<h3>2.Machupichu</h3><center>

<img src="machupicchu.jpg" width=500 height=250></center>

</body>

</html>

OUTPUT:

 

6

Page 7: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 7/38

WPSLAB

PROGRAM:6  PROGRAM TO DEMONSTRATE FRAMES

<html>

<head><title>Frames</title>

</head>

<frameset cols="40%,60%">

<frame src="lists.html">

<frameset rows="30%,70%">

<frame src="colosseum.jpg">

<frame src="images.html">

</frameset>

</frameset></html>

OUTPUT:

7

Page 8: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 8/38

WPSLAB

PROGRAM:7 Formatted text using tables

<html>

<head> <title> formatting text using tables</title>

<table border=10 width=100%>

<tr>

<td> <font color=purple font size=10> CBIT </font> </td>

<td>

<img src="CBIT.png" width=100 height=100></td>

</tr>

<tr>

<td> <font color=blue> CSE </font> </td>

<td> <font color=blue> ECE </FONT> </TD>

</tr>

<tr>

<td> <table border=1 width=50% bgcolor=lavender cellpadding=20

cellspacing=15>

<tr> <td> BRANCH </td>

<td> ROLL NO </td>

</tr>

<tr> <td> CSE </td><td> 8063</td>

</tr>

<tr>

<td> ECE </td>

<td>4012 </td>

</tr>

</table>

</td>

<td> DEPARTMENTS AND ROLLNO.s OF STUDENTS </td></tr>

</table>

</html>

8

Page 9: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 9/38

WPSLAB

OUTPUT:

 

9

Page 10: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 10/38

WPSLAB

PROGRAM:8 FORMS

<html>

<head><title>Form</title>

</head>

<body>

<table border=0 width=100% cellspacing=5 cellpadding=10>

<tr>

<td>

<table border=0 cellspacing=5 cellpadding=10><tr>

<td><u><b>YAHOO!</b></u></td>

</tr>

<tr>

<td>Username</td><td><input type=text

name=Username></td>

</tr>

<tr>

<td>Password</td><td><input type=password ></td></tr>

<tr>

<td><input type=checkbox >

Remember password ?</td>

</tr>

<tr>

<td><input type=button name=login value=LOGIN>

<input type=button name=cancel value=cancel ></td>

</tr>

</table>

</td>

<td>

<table border=0 cellspacing=5 cellpadding=10>

<tr>

<td><b><u>GOOGLE</u></b></td>

</tr>

<tr>

<td>Username</td><td><input type=text name=Username></td>

</tr><tr>

10

Page 11: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 11/38

WPSLAB

<td>Password</td><td><input type=password ></td>

</tr>

<tr>

<td><input type=checkbox >

Remember password ?</td></tr>

<tr>

<td><input type=button name=login value=LOGIN>

<input type=button name=cancel value=cancel ></td>

</tr>

</table>

</td>

</tr>

</table>

</body>

</html>

OUTPUT:

11

Page 12: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 12/38

WPSLAB

PROGRAM:9 Program to perform arithmetic operations

using Javascript

<!---arithmetic operations using javascript-->

<html>

<head><title>Arithmetic operations</title>

<script type=text/javascript>

function addition(a,b)

{

var a,b,c;

a=parseInt(document.fm.fa.value);b=parseInt(document.fm.fb.value);

c=a+b;

document.fm.fc.value=c;

}

function subtraction(a,b)

{

var a,b,c;

a=parseInt(document.fm.fa.value);

b=parseInt(document.fm.fb.value);c=a-b;

document.fm.fc.value=c;

}

function multiplication(a,b)

{

var a,b,c;

a=parseInt(document.fm.fa.value);

b=parseInt(document.fm.fb.value);

c=a*b;document.fm.fc.value=c;

}

function division(a,b)

{

var a,b,c;

a=parseInt(document.fm.fa.value);

b=parseInt(document.fm.fb.value);

c=a/b;

document.fm.fc.value=c;

}

12

Page 13: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 13/38

WPSLAB

</script>

</head>

<body>

<form name=fm><h3>a</h3>

<input type=text name=fa>

<h3>b</h3>

<input type=text name=fb><br/>

<h3>c</h3>

<input type=text name=fc><br/><br/>

<input type=button value=add onclick=addition()>

<input type=button value=sub onclick=subtraction()>

<input type=button value=mul onclick=multiplication()>

<input type=button value=div onclick=division()>

</form>

</body>

</html>

OUTPUT:

13

Page 14: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 14/38

WPSLAB

PROGRAM:10 PROGRAM TO VALIDATE WEBADDRESS, EMAIL

USING JAVASCRIPT

<html>

<head><title>test memail id and web</title></head>

<script type="text/javascript">

function testMailIDandWeb()

{

var a,b;

a=document.test.aval.value;

b=document.test.bval.value;

var p=a.search(/\w\@\w+\.com/);

var q=b.search(/www\.\w+\.\w+/);

if(p>=0)

{

if(q>=0)

document.writeln("VALID MAIL and WEB");

else

document.writeln("INVALID web");

}

else

{

if(q>=0)

document.writeln("INVALID mail");

else

document.writeln("INVALID MAIL ID AND WEB");

}

}

</script></head>

<body>

<form name="test">

<h3>ENTER MAIL ID:</h3>

<input type=text name=aval><br/>

<h3>ENTER WEB ADDRESS</h3>

<input type=text name=bval><br/>

<input type=button value="TEST"onClick=testMailIDandWeb()>

</form>

</body>

</html>

14

Page 15: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 15/38

WPSLAB

OUTPUT:

 

15

Page 16: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 16/38

WPSLAB

PROGRAM:11  PASSWORDCHECK USING EVENTHANDLING

<!---pswd.html--->

<html>

<head>

<title>validation</title>

<script type="text/javascript" src="pswdcheck.js">

</script>

</head>

<body>

<h1>password check</h1>

<form id="passwordform" action=" ">

<p>enter password</p>

<input type="password" id="first">

<p>Verify password</p>

<input type="password" id="second"><br/>

<input type=reset value=reset>

<input type=button value=submit onclick=passwordcheck()>

</form>

<script type="text/javascript" src="regevent.js">

</script>

</body>

</html>

<!---pswd.js--- >

function passwordcheck()

{

var one=document.getElementById("first");

var two=document.getElementById("second");

if(one.value =="")

{

alert("You havenot enter the password\n"+"Please enter it");

one.focus();

return false;

}

if(one.value!=two.value)

{

alert(" Passwords donot match\n"+"Enter both fields again");one.focus();

16

Page 17: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 17/38

WPSLAB

one.select();

return false;

}

else

return true;

}

<!-----regevent.js- ->

document.getElmentById("second").onblur=passwordcheck();

document.getElementById("passwordform").onsubmit=passwordcheck();

OUTPUT:

 

17

Page 18: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 18/38

WPSLAB

PROGRAM:12 DHTML positioning

I. ABSOLUTE POSITIONING:

<html>

<head><title>Absolute positioning</title>

<style type="text/css">

.regtext{font-family:arial;font-size:30pt;width=600px;

position:absolute;top:125px;left:100px; }

.abstext{position:absolute;Top:10px;left:50px;

font-family:italic;letter-spacing:lem;font-size:36pt;

color:teal;width:400px;}</style>

</head>

<body>

<div class="regtext">

Dynamic XHTML is not a markup language.It is a collection of technologies

that allows dynamic changes to documents described with XHTML.

<span class="abstext">

 This is an example for ABSOLUTE positioning

</span></div>

</body>

</html>

OUTPUT:

18

Page 19: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 19/38

WPSLAB

II. RELATIVE POSITIONING:

<html>

<head><title>Relative positioning</title></head>

<body style="font-family:times;font-size=24pt;">

<p>

This is an example for illustrating<span style="position:relative;Top:10px;

font-family:times;font-style:italic;font-size:24pt;color:red;">

RELATIVE POSITIONING</span> of elements.

</p>

<body>

</html>

OUTPUT:

19

Page 20: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 20/38

WPSLAB

PROGRAM:13 DHTML CHANGING COLORS

<!----DHTMLcolor.html----->

<html>

<head><title>Dynamic colors</title>

<script type="text/javascript" src="dyncolors.js">

</script>

</head>

<body>

<p style="font-family:times;font-style:italic;font-size:24pt">

 This small page illustrates dynamic setting of the foreground and

background colors for a document

</p>

<form action=" ">

<p>

<label>Background color

<input type="text" name="background" size="10"

onchange="setColor('background',this.value)">

20

Page 21: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 21/38

WPSLAB

</label>

<label>Foreground color

<input type="text" name="foreground" size="10"

onchange="setColor('foreground',this.value)">

</label><br/>

</p>

</form>

</body>

</html>

<!---dyncolors.js --- >

function setColor(where,newColor)

{

if(where=="background")

document.body.style.backgroundColor=newColor;

else

document.body.style.color=newColor;

}

OUTPUT:

21

Page 22: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 22/38

WPSLAB

PROGRAM:14 WELL FORMED AND VALID XML DOCUMENT

<!----Well formed Xml---- >

22

Page 23: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 23/38

WPSLAB

<?xml version="1.0" ?>

<subjectlist>

<sub>

<title>WPS</title>

<reference>WEB programming by Sebesta</reference></sub>

<sub>

<title>OOSD</title>

<reference>UML user guide by GRADY BOOCH</reference>

</sub>

<sub>

<title>ALGORITHMS</title>

<reference>Computer algorithms by sahni</reference>

</sub>

</subjectlist>

OUTPUT:

<!---VALID XML ------ >

Using internal DTD:

<?xml version="1.0" ?>

<!DOCTYPE ORGANISATION [

23

Page 24: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 24/38

WPSLAB

<!ELEMENT ORGANISATION (EMPLOYEE+)>

<!ELEMENT EMPLOYEE (EMPID?,EMPNAME+,EMPDESIGNATION*)>

<!ELEMENT EMPID (#PCDATA) >

<!ELEMENT EMPNAME (#PCDATA)>

<!ELEMENT EMPDESIGNATION (#PCDATA)><!ATTLIST PLACE NAME CDATA #REQUIRED>

]>

<ORGANISATION>

<EMPLOYEE>

<EMPID>555</EMPID>

<EMPNAME>CLARK</EMPNAME>

<EMPDESIGNATION>SE</EMPDESIGNATION>

<PLACE NAME = "HYD" >AP</PLACE>

</EMPLOYEE>

<EMPLOYEE>

<EMPID>666</EMPID>

<EMPNAME>ROBBIN</EMPNAME>

<EMPDESIGNATION>TE</EMPDESIGNATION>

<PLACE NAME = "NEWYORK">US</PLACE>

</EMPLOYEE>

</ORGANISATION>

EXAMPLE2:

<!---External DTD------- >

<?xml version="1.0" ?>

<!DOCTYPE ORGANISATION SYSTEM "Employee.dtd">

<ORGANISATION>

<EMPLOYEE>

<EMPID>555</EMPID>

<EMPNAME>CLARK</EMPNAME>

<EMPDESIGNATION>SE</EMPDESIGNATION>

<PLACE NAME = "HYD" >AP</PLACE>

</EMPLOYEE>

<EMPLOYEE>

<EMPID>666</EMPID>

<EMPNAME>ROB</EMPNAME>

<EMPDESIGNATION>TE</EMPDESIGNATION>

<PLACE NAME = "NEWYORK">US</PLACE>

</EMPLOYEE>

</ORGANISATION>

<!----------Employee.dtd--- >

24

Page 25: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 25/38

WPSLAB

<!ELEMENT ORGANISATION (EMPLOYEE+)>

<!ELEMENT EMPLOYEE (EMPID?,EMPNAME+,EMPDESIGNATION*)>

<!ELEMENT EMPID (#PCDATA) >

<!ELEMENT EMPNAME (#PCDATA)>

<!ELEMENT EMPDESIGNATION (#PCDATA)>

<!ATTLIST PLACE NAME CDATA #REQUIRED>

OUTPUT:

 

PROGRAM:15 XSLT

<!---xml document--->

<?xml version="1.0" ?>

25

Page 26: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 26/38

WPSLAB

<?xml-stylesheet type="text/xsl" href="xslt.xsl"?>

<subject>

<sub>

<title>WPS</title>

<reference>WEB programming by Sebesta</reference></sub>

<sub>

<title>OOSD</title>

<reference>UML user guide by GRADY

BOOCH</reference>

</sub>

<sub>

<title>ALGORITHMS</title>

<reference>Computer algorithms by sahni</reference>

</sub>

<sub>

<title>PPL</title>

<reference>PPL by RaviSethi</reference>

</sub>

</subject>

 The following XSLT stylesheet processes previous XML document

<!---------xslt.xsl--- >

<?xml version="1.0" ?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<html>

<body>

<h2>SUBJECT DETAILS</h2>

<table border="1">

<tr bgcolor="lavender"><th>TITLE</th>

<th>REFERENCE</th>

</tr>

<xsl:for-each select="subject/sub">

<tr>

<td><xsl:value-of select="title" /></td>

<td><xsl:value-of select="reference" /> </td>

</tr>

</xsl:for-each></table>

26

Page 27: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 27/38

WPSLAB

</body>

</html>

</xsl:template>

</xsl:stylesheet>

OUTPUT:

 

PROGRAM:16  Retrieving information using

ACTIVEXOBJECT(XMLDOM)

<html>

<head><title> XML DOM</title>

</head>

<body><script type="text/javascript">

27

Page 28: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 28/38

WPSLAB

function sublistinfo()

{

xmlDoc= new ActiveXObject("Microsoft.XMLDOM");

xmlDoc.load("sublist.xml");

x=xmlDoc.getElementsByTagName("sub")[0];document.writeln("SUBJECT DETAILS"+"<br/>");

document.writeln("TITLE:"+x.firstChild.childNodes[0].nodeValue+"<br/>");

document.writeln("REFERENCE:"+x.lastChild.childNodes[0].nodeValue);

document.writeln("<br/>"+"NEXT SUBJECT DETAILS "+"<br/>");

document.writeln("TITLE:"+x.nextSibling.firstChild.childNodes[0].nodeValue

+"<br/>");

document.writeln("REFERENCE:"+x.nextSibling.lastChild.childNodes[0].node

Value);

}

</script>

<form>

<input type="button" name=click value=click onclick="sublistinfo()">

</body>

</html>

<!---sublist.xml--->

<?xml version="1.0" ?>

<subjectlist>

<sub>

<title>WPS</title>

<reference>WEB programming by Sebesta</reference>

</sub>

<sub>

<title>OOSD</title>

<reference>UML user guide by GRADY BOOCH</reference>

</sub><sub>

<title>ALGORITHMS</title>

<reference>Computer algorithms by sahni</reference>

</sub>

<sub>

<title>PPL</title>

<reference>PPL by RaviSethi</reference>

</sub>

</subjectlist>

28

Page 29: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 29/38

WPSLAB

OUTPUT:

 

PROGRAM:17 CREATING A TABLE USING JDBC

/*Program to create a table*/

import java.sql.*;

public class CreateStudent

{public static void main(String[] args)

29

Page 30: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 30/38

WPSLAB

{

Connection con = null;

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");con =DriverManager.getConnection("jdbc:odbc:STUDENTDB");

// Creating a database table

Statement stmt = con.createStatement();

int count = stmt.executeUpdate(

"CREATE TABLE Studenttable (STID INT, STUname VARCHAR(20))");

System.out.println("Table created.");

stmt.close();

con.close();

}

catch(IOException e)

{

System.out.println(e.toString());

}

catch(ClassNotFoundException e)

{

System.out.println("CLASS NOT FOUND");

}

}

}

OUTPUT:

30

Page 31: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 31/38

WPSLAB

31

Page 32: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 32/38

WPSLAB

PROGRAM:18  INSERTION INTO A TABLE USING JDBC

//program to insert rows

import java.sql.*;

public class InsertRows{

public static void main(String [] args)

{

Connection con = null;

try

{

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

con = DriverManager.getConnection("jdbc:odbc:STUDENTDB");

Statement sta = con.createStatement();int count = 0;

int c ;

c= sta.executeUpdate("INSERT INTO Studenttable (STID, STUname)

VALUES(1,'Aparna')");

count = count + c;

c = sta.executeUpdate("INSERT INTO Studenttable (STID, STUname)

VALUES (2,'Anusha')");

count = count + c;

c = sta.executeUpdate("INSERT INTO Studenttable (STID, STUname)

VALUES (3,'Anjali')");

count = count + c;

System.out.println("Number of rows inserted: "+count);

sta.close();

con.close();

}

catch(IOException e)

{

System.out.println(e.toString());

}catch(ClassNotFoundException e)

{

System.out.println("CLASS NOT FOUND");

}

}

}

32

Page 33: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 33/38

WPSLAB

OUTPUT:

33

Page 34: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 34/38

Page 35: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 35/38

WPSLAB

catch(SQLException e)

{

System.out.println(e.toString());

}

}}

OUTPUT:

PROGRAM 20  BASIC SERVLET EXAMPLE

35

Page 36: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 36/38

WPSLAB

import java.io.*;

import javax.servlet.*;

public class BasicServlet extends GenericServlet

{public void service(ServletRequest req, ServletResponse res) throws

ServletException, IOException

{

res.setContentType("text/html");

PrintWriter out=res.getWriter();

out.println("<html>");

out.println("<head><title>Basic servlet example</title></head>");

out.println("<body >");

out.println("<h1 align=center> K.APARNA</h1>");

out.println("<h2 align=center>02078063</h2>");

out.println("</body>");

out.println("</html>");

}

}

OUTPUT:

PROGRAM:21 SERVLET FORM PROGRAM

<html>

36

Page 37: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 37/38

WPSLAB

<head><title>Form</title></head>

<body>

<form name="form1" method=post

action="http://localhost:8080/servlets-examples/servlet/FormExample">

<p>Studentname</p><input type=text name=N>

<p>Rollno</p>

<input type=text name=R>

<p>Branch</p>

<input type=text name=B>

<input type=submit value=submit>

<input type=reset value =reset>

</form>

<body>

</html>

<!-----FormExample.java---->

import java.io.*;

import java.text.*;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class FormExample extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse

response)

throws IOException, ServletException

{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

String a=request.getParameter("N");

String b=request.getParameter("R");String c=request.getParameter("B");

out.println("<html><body>");

out.println("<h3>U have just entered the following<h3><br/>");

out.println("Studentname:"+a+"<br/>");

out.println("Rollno:"+b+"<br/>");

out.println("Branch:"+c+"<br/>");

}

}

OUTPUT:

37

Page 38: WPS RECORD PROGRAMS

8/9/2019 WPS RECORD PROGRAMS

http://slidepdf.com/reader/full/wps-record-programs 38/38

WPSLAB

When all the fields are entered and submitted,the following HTML page

displays