0% found this document useful (0 votes)
85 views

Webtech Record

The document contains code to implement various HTML and JavaScript concepts. It includes 7 sections with the aims of implementing frames, an online bookstore, registration and login forms, a books catalogue, shopping cart, payment details, and order confirmation pages using HTML. It also includes code examples to demonstrate inline and embedded style sheets, an external style sheet, and a JavaScript program to calculate the sum of two numbers and find the minimum and maximum values in an array.

Uploaded by

Hari Raman
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Webtech Record

The document contains code to implement various HTML and JavaScript concepts. It includes 7 sections with the aims of implementing frames, an online bookstore, registration and login forms, a books catalogue, shopping cart, payment details, and order confirmation pages using HTML. It also includes code examples to demonstrate inline and embedded style sheets, an external style sheet, and a JavaScript program to calculate the sum of two numbers and find the minimum and maximum values in an array.

Uploaded by

Hari Raman
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 93

1

1.Aim: To implement Frames


Source code:
<html>
<head>
<title>
FRAMES
</title>
<frameset cols="500,*">
<frame src="first.html" name=h1>
<frame src="olul.html" name=h2>
</frameset>
</html>

First frame:
<HTML>
<Head>
<title>
first page of html
</title>
</head>
<body>
<h1><b><i><u>this is my first lab of html</b></i></u></h1>
</body>
<html>

Second frame:
<html>
<head>
<title>
ordered and unoredered lists
</title>
2

</head>
<body>
<ol type=1>
<li>b-tech </li>
<li> mca </li>
<li> mba </li>
</ol>
<ul>
<li> cse </li>
<li> it </li>
<li> ece </li>
<li> eee </li>
</ul>
</body>
<html>
3

Output:
4

2.Aim: To implement Online Bookstore


Source code :
<html>
<head>
<title>
online bookstore
</title>
</head>
<body>
<body bgcolor="gray">
<marquee><h1>ONLINE BOOKSHOPPING</h1></marquee>
<ul>
<li>
<b>
<a href="registration.html"><u>registration</u></a></li><br><br>
<li>
<a href="login.html"><u>login</u></a></li><br><br>
<li>
<a href="profile.html"><u>profile</u></a></li><br><br>
<li>
<a href="catalogue.html"><u>books catalogue</u></a></li><br><br>
<li>
<a href="shopcart.html"><u>shopping cart</u></a></li><br><br>
<li>
<a href="payment.html"><u>payment by credit</u></a></li><br><br>
<li>
<a href="oconfirm.html"><u>order confirmation</u></a></li><br><br>
</b>
</body>
</html>
5

Output :
6

2.1.Aim:To design Registration form


Source code:
<html>
<head>
<title>
REGISTRATION FORM
</title>
<script language="javascript">
function check()
{
if((f.txtuser.value.indexOf("."))-(f.txtuser.value.indexOf("@"))<=1||
(f.txtuser.value.indexOf("@"))==0)
{
window.alert("invalid email id");
f.txtuser.focus();
f.txtuser.value="";
}
function text_box()
{
if(f.txtpwd.value!=f.txtconfpwd.value)
{
window.alert("enter correct pwd");
f.txtpwd.value="";
f.txtconfpwd.value="";
f.txtpwd.focus();
}
}
function button_check()
{
7

if((f.c3.checked!=true)&&(f.c2.checked!=true)&&(f.c1.checked!=true))
{
window.alert(" select a checkbox");
}
}
function check_radio()
{
if((f.c1[0].checked!=true)&&(f.c1[1].checked!=true)&&(f.c1[2].checked!=true))
{
window.alert("select only one option");
}
}
}
</script>
<body>
<form name="f" method="get">
<body bgcolor="pink">
<h1 align=center >REGISTRATION FORM</h1>
username:<input type="text" name=txtname size=30>
<br>
email id:<input type="text" name=txtuser size=30 onBlur="check()">
<br>
password:<input type="password" name=txtpwd size=30 >
<br>
confirmpassword:<input type="password" name=txtconfpwd size=20 onBlur=" text_box()"><br>
<h1><u>HOBBIES</u></h1>
cricket:<input type="checkbox" name=c1>
<br>
hockey:<input type="checkbox" name=c2>
<br>
baseball:<input type="checkbox" name=c3 onBlur="button_check()">
8

<br>
<h1><u>course</u></h1>
b-tech:<input type="radio" name=c1>
<br>
mba:<input type="radio" name=c1>
<br>
mca:<input type="radio" name=c1 onBlur="check_radio()">
<br>
<br>
<b>CITY</b>:<select type=city>
<option>hyd </option>
<option>vijayawada </option>
<option>kurnool</option>
<option>anatapur</option></select>
<br>
<center>
<input type="button" name="b" value="enter">
<input type=reset value=cancel name=b2></center>
</form>
</body>
</html>
9

Output:
10

2.2.Aim: To design Login Form


Source code:
<html>
<head>
<title>
LOGIN
</title>
</head>
<body>
<body bgcolor="pink">
<h1>login</h1>
<center >username:<input type="text" name=txtuser size=30></center>
<br>
<center>password:<input type="password" name=password size=30></center>
<br>
<center><input type=submit value=submit name=b1>
<input type=reset value=cancel name=b2></center>
</body>
</html>
11

Output:

2.3.Aim: To design the Profile page


Source code:
<html>
<head>
<title>
Profile
</title>
</head>
<body>
<body bgcolor="yellow">
<h1>Profile</h1>
<p>
username:drk<br>
12

email id:[email protected]
</p>
<a href="online.html"><u>homepage</u></a></li>
</body>
</html>

Output:
13

2.4.Aim: To design the Books Catalogue page


Source code:
<html>
<head>
<title>
Bookscatalogue
</title>
</head>
<body>
<body bgcolor="brown">
<p>
<b>B-TECH</b><br>
<br>
web-tech:<input type="checkbox" name=c1>
<br>
Mobile Computing:<input type="checkbox" name=c2>
<br>
SPM:<input type="checkbox" name=c3>
<br>
DMDW:<input type="checkbox" name=c4>
<br>
<br>
<b>.Net</b>
<br>
<br>
C#.Net:<input type="checkbox" name=c5><br>
VB.Net:<input type="checkbox" name=c6><br>
ASP.Net:<input type="checkbox" name=c7><br>
</p>
<br>
<a href="online.html"><u>homepage</u></a>
14

</body>
</html>
Output:
15

2.5.Aim: designing the Shopping cart page


Source code:
<html>
<head>
<title>
ShopCart
</title>
</head>
<body>
<body bgcolor="yellow">
<p>
<b>You Ordered:
<br>
<ol type=1>
<li>web-tech price=$10</li>
<li>Mobile Computing Price=$12</li>
<li>SPM Price=$15</li>
<li>DMDW Price=$20 </li>
<li>ASP.Net Price=$10</li>
<li>VB.Net Price=$8</li>
<li>C#.Net Price=$10</li>
</ol>
</p>
<br>
<a href="online.html"><u>homepage</u></a>
</body>
</html>
16

Output:
17

2.6.Aim: To input the Payment details


Source code:
<html>
<head>
<title>
Payment
</title>
</head>
<body>
<body bgcolor="teal">
<p>
Enter Credit card Details:
</p>
<center >card number:<input type="text" name=txtuser size=30></center>
<center>Email id:<input type="text" name=email id size=30></center>
<center>password:<input type="password" name=password size=30></center>
<center >Total amount:<input type="text" name=txtuser size=30></center>
<center>card expirydate:<input type="text" name=validity size=30></center>
<br>
<center><input type=submit value=submit name=b1>
<input type=reset value=cancel name=b2></center>
<br>
<br>
<a href="online.html"><u>homepage</u></a>
</body>
</html>
18

Output:
19

2.7.Aim: To confirm the Order details


Source code:
<html>
<head>
<title>
Order
</title>
</head>
<body>
<body bgcolor="pink">
<h1>Address:</h1>
<p>
Enter Address:<input type="text" name=txtuser size=30><br>
<b>CITY</b>:<select type=city>
<option>hyd </option>
<option>vijayawada </option>
<option>kurnool</option>
<option>anatapur</option></select>
<br>
<b>State</b>:<select type=state>
<option>Ap</option>
<option>Kerala</option>
<option>karnataka</option>
<option>Tamilnadu</option></select>
<br>
</p>
<center><input type=submit value=confirm name=b1></center>
<br><br>
<a href="online.html"><u>homepage</u></a>
</body>
</html
20

Output:
21

3.Aim: To design the Inline style sheet


Source code:
<html>
<head>
<title>
inline style sheet
</title>
</head>
<body>
<p style="font-size:20pt">
this is an example
</p>
<p style="font-size:30pt;color:red">
this is second p tag
</p>
</body>
</html>
22

Output:
23

4.Aim: To implement Embedded Style sheet


Source code:
<html>
<head>
<title>
embedded style sheet
</title>
<style type="text/css">
h1{font-size:30pt;color:red;background-color:yellow}
p{font-size:15pt}
p.blue{color:blue}
h1.obj{font-style:italic}
</style>
</head>
<body>
<h1 class=obj>
this is example of h1 tag
</h1>
<p>
this is p tag
</p>
<h1>
this is second h1 tag
</h1>
<p class=blue>
this is demo for p element
</p>
</body>
</html>
24

Output:
25

5.Aim: To implement External Style sheet

Source code:

CSS file:
a:hover{text-decoration:underline;color:red;background-color:blue}
h1 em{color:red}
li em{color:yellow;background-color:red;font-weight:bold}
ul {margin-left:2cm;color:red}
ul ul{text-decoration:underline;margin-left:1.5cm;color:yellow}

HTML file:

<html>
<head>
<title>external</tilte>
<link type="text/css" rel="stylesheet" href="file.css">
</head>
<h1>courses offered in <em>DRKIST</em></h1>
<ul>
<li>
mca</li>
<li>
b-tech
<ul>
<li>cse</li>
<li>ece</li>
<li>eee</li>
</ul>
</li>
<li>mba</li>
<li>m-tech</li>
26

<li>m-tech<em>:specialisation S/w Engineering</em></li>


</ul>
<a href "http:homepage.html">homepage.html</a>
</html>
Output:
27

6.Aim: To implement Sum of two numbers-java script


Source code:
<html>
<head>
<title>
javascript
</title>
<script language="javascript">
var first,sec,num;
first=window.prompt("enter first string","0");
var n1=parseInt(first);
second=window.prompt("enter second string","0");
var n2=parseInt(second);
sum=n1+n2;
document.writeln("<h1>sum of 2 values"+sum+"</h1>");
</script>
</html>
28

Output:
29
30

7.Aim: Min-Max(java script)

Source code:

<html>
<head>
<title> max & min </title>
<script language="javascript">
var max,min,i,j,l,temp,n;
n=new Array(10);
for(i=0;i<n.length;i++)
{
n[i]=parseInt(window.prompt("enter element "+i+""));
}
document.writeln("array elements before sorting are:");
document.writeln("<br>");
for(i=0;i<n.length;i++)
{
document.writeln(""+n[i]+",");
}
for(i=0;i<n.length;i++)
{
for(j=i+1;j<n.length;j++)
{
if(n[i]>n[j])
{
temp=n[i];
n[i]=n[j];
n[j]=temp;

}
31

document.writeln("<br>");
document.writeln("array elements after sorting are:");
for(i=0;i<n.length;i++)
{
document.writeln(","+n[i]+"");
}
document.writeln("<br>");
document.writeln("max element is "+n[9]+"");
document.writeln("<br>");
document.writeln("min element is "+n[0]+"");
document.writeln("<br>");
k=parseInt(window.prompt("enter element to be searched:","0"));
document.writeln("<br>");
for(i=0;i<n.length;i++)
{
j=i+1;
if(k==n[i])
{
l=1;
document.writeln("element found at position "+j+"");
}
}
if(l!=1)
document.writeln("element not found");
</script>
32

Output:
33
34
35

8.Aim: To display Multiplication table

Source code:

<html>
<head>
<title>
multiplication table
</title>
<script language="javascript">
var num;
first=window.prompt("enter number:");
var n1=parseInt(first);
document.writeln("<h1 align=center>multiplication table</h1>");
document.writeln("<table border=1 align=center width=20%>");
for(var i=1;i<=10;i++)
document.writeln("<tr><td>"+n1+"</td><td>"+i+"</td><td>"+mult(i)+"</td></tr>");
document.writeln("</table>");
function mult(i)
{
if(i<1)
return 1;
else
return n1*i;
}
</script>
</head>
</html>
36

Output:
37

9.Aim: To show Factorial of 10 numbers

Source code:
<html>
<head>
<title>
web page
</title>
<script language="javascript">
document.writeln("<h1>factorial of 1 to 10 numbers</h1>");
document.writeln("<table border='2' width='10%'>");
for(var i=1;i<=10;i++)
document.writeln("<tr><td>"+i+"</td><td>"+fact(i)+"</td></tr>");
document.writeln("</table>");
function fact(i)
{
if(i<=1)
return 1;
else
return i*fact(i-1);
}
</script>
</head>
<body bgcolor="yellow">
</body>
</html>
38

Output:
39

10.Aim: Validating a textbox


Source code:
<html>
<head>
<title>
validating a textbox
</title>
<script language="javascript">
function button_click()
{
if(f.b.value=" ")
{
window.alert("button clicked");
}}
</script>
<body>
<form name="f">
<input type="button" name="b" value="enter" onBlur="button_click()">
</form>
</body>
</html>
40

Output:
41

11.Aim:Validating a checkbox
Source code:
<html>
<head>
<title> validating checkbox </title>
<script language="javascript">
function button_check()
{
if((f.c3.checked!=true)&&(f.c2.checked!=true)&&(f.c1.checked!=true))
{
window.alert(" select a checkbox");
}
}
</script>
<body>
<form name="f">
<input type="checkbox" name=c1>playing <br>
<input type="checkbox" name=c2>reading <br>
<input type="checkbox" name=c3>studying <br>
<input type="button" name="b" value="enter" onBlur="button_check()">
</body>
</html>
42

Output:
43

12.Aim: Validating a radio button


Source code:
<html>
<head>
<title> </title>
<script language="javascript">
function f1()
{
if((f.r1[0].checked!=true)||(f.r1[1].checked!=true)||(f.r1[2].checked!=true))
{
window.alert("please select single option");
}
}</script></head>
<body><form name="f" Action="get">
<input type="radio" name="r1">b.tech<br></br>
<input type="radio" name="r1"onBlur="f1( )">m.b.a<br></br>
<input type="radio" name="r1" onBlur="f1( )">m.c.a<br></br>
</form>
</body>
</html>
44

Output:
45

13.Aim: Validating password


Source code:
<html>
<head>
<title>
password validation
</title>
<script language="javascript">
document.writeln("validation");
function text_box()
{
if(f.txtpwd.value!=f.txtconfpwd.value)
{
window.alert("enter correct pwd");
f.txtpwd.value="";
f.txtconfpwd.value="";
f.txtpwd.focus();

}
}
</script>
<body>
<form name="f" method="get">
password:<input type="password" name=txtpwd size=20><br>
confirmpassword:<input type="password" name=txtconfpwd size=20><br>
<input type="button" name="b" value="enter" onBlur="text_box()">
</form>
</body>
</html>
46

Output:
47

14.Aim: Validating an e-mail ID

Source code:

<html>
<head>
<title>
Email validation
</title>
<script language="javascript">
document.writeln("validation");
function check()
{
if((f.txtname.value.indexOf("."))-(f.txtname.value.indexOf("@"))<=1||
(f.txtname.value.indexOf("@"))==0)
{
window.alert("invalid email id");
f.txtname.value="";
f.txtname.focus();
}
}
</script>
<body>
<form name="f" method="get">
email id:<input type="text" name="txtname" size=20 onBlur="check()"><br>
password:<input type="password" name=pwd size=20 ><br>
</form>
</body>
</html>
48

Output:
49

15.Aim: To implement Internal DTD

Source code:

<?xml version="1.0" ?>


<!DOCTYPE DOCUMENT[
<!ELEMENT DOCUMENT (customer)*>
<!ELEMENT customer (name,date,order)>
<!ELEMENT name (last_name,first_name)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT order (items)*>
<!ELEMENT item (product,quantity,price)>
<!ELEMENT product (#PCDATA)>
<!ELEMENT quantity (#PCDATA)>
<!ELEMENT price (#PCDATA)>
]>
<DOCUMENT>
<customer>
<name>
<last_name>def</last_name>
<first_name>abc</first_name>
</name>
<date>Aug 25th 2009</date>
<order>
<item>
<product>books</product>
<quantity>5</quantity>
<price>500</price>
</item>
</order>
50

</customer>
<customer>
<name>
<last_name>asdf</last_name>
<first_name>asde</first_name>
</name>
<date>Aug 26th 2009</date>
<order>
<item>
<product>pens</product>
<quantity>50</quantity>
<price>5000</price>
</item>
</order>
</customer>
<customer>
<name>
<last_name>def</last_name>
<first_name>abc</first_name>
</name>
<date>Aug 27th 2009</date>
</customer>
51

Output:
52

16.Aim: To implement External DTD

Source code:
<!ELEMENT DOCUMENT (customer)*>
<!ELEMENT customer (name,date,order)>
<!ELEMENT name (last_name,first_name)>
<!ELEMENT last_name (#PCDATA)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT order (items)*>
<!ELEMENT item (product,quantity,price)>
<!ELEMENT product (#PCDATA)>
<!ELEMENT quantity (#PCDATA)>
<!ELEMENT price (#PCDATA)>

XML file:

<?xml version="1.0" ?>

<!DOCTYPE customer SYSTEM "customer.dtd">

<DOCUMENT>

<customer>

<name>

<last_name>def</last_name>

<first_name>abc</first_name>

</name>

<date>Aug 25th 2009</date>

<order>

<item>

<product>books</product>
53

<quantity>5</quantity>

<price>500</price>

</item>

</order>

</customer>

<customer>

<name>

<last_name>asdf</last_name>

<first_name>asde</first_name>

</name>

<date>Aug 26th 2009</date>

<order>

<item>

<product>pens</product>

<quantity>50</quantity>

<price>5000</price>

</item>

</order>

</customer>

<customer>

<name>

<last_name>def</last_name>
54

<first_name>abc</first_name>

</name>

<date>Aug 27th 2009</date>

<order>

<item>

<product>bags</product>

<quantity>15</quantity>

<price>2500</price>

</item>

</order></customer>

</DOCUMENT>
55

Output:
56

17.Aim: Accessing data from XML file

Source code:

<students>

<student>

<stuno>101</stuno>

<stuname>raghu</stuname>

<dept>cse</dept>

<marks>100</marks>

</student>

<student>

<stuno>102</stuno>

<stuname>dileep</stuname>

<dept>cse</dept>

<marks>99</marks>

</student>

<student>

<stuno>103</stuno>

<stuname>vijay</stuname>

<dept>cse</dept>

<marks>99</marks>

</student>
57

<student>

<stuno>104</stuno>

<stuname>pradeep</stuname>

<dept>cse</dept>

<marks>100</marks>

</student>

<student>

<stuno>105</stuno>

<stuname>pradeep</stuname>

<dept>cse</dept>

<marks>100</marks>

</student>

<student>

<stuno>106</stuno>

<stuname>shashi</stuname>

<dept>cse</dept>

<marks>100</marks>

</student>

<student>

<stuno>107</stuno>

<stuname>venky</stuname>
58

<dept>cse</dept>

<marks>100</marks>

</student>

<student>

<stuno>108</stuno>

<stuname>bharath</stuname>

<dept>cse</dept>

<marks>99</marks>

</student></students>

HTML file:

<html>
<head>
<title>
student record
</title>
<script language="javascript">
function fun_first()
{
p.recordset.moveFirst();
}
function fun_next()
{
p.recordset.moveNext();
if(p.recordset.EOF)
{
window.alert("it is last record");
}
}
59

function fun_last()
{
p.recordset.moveLast();
}
function fun_previous()
{
p.recordset.movePrevious();
if(p.recordset.BOF)
{
window.alert("it is frist record");
}
}
</script>
<body>
<form name="f">
<xml id="p" src="stud.xml">
</xml>
studentno:<input type="text" name="t1" datafld="stuno" datasrc="#p"><br>
studentname:<input type="text" name="t2" datafld="stuname" datasrc="#p"><br>
dept:<input type="text" name="t3" datafld="dept" datasrc="#p"><br>
studentmarks:<input type="text" name="t4" datafld="marks" datasrc="#p"><br>
<input type="button" value="first" name="first" onClick="fun_first()">
<input type="button" value="last" name="last" onClick="fun_last()">
<input type="button" value="previous" name="previous" onClick="fun_previous()">
<input type="button" value="next" name="next" onClick="fun_next()">
</form>
</body>
</html>
60

Output:
61
62

18.Aim: To write Style.css file

Source code:
name
{
font-family:"Times New Roman";
font-size="8pt";
color:"black";
}
date
{
font-family:"Verdana";
font-size="16 pt";
color:"blue";
}
orders
{
font-family:"Monotype Corsiva";
font-size="24 pt";
color:"green";
}

XML file:
<?xml version ="1.0" ?>
<?xml-stylesheets Type="text/css" href="styl.css"?>
<Document>
<customer>
<name><last_name>nadella</last_name><first_name>siddhartha</first_name></name>
<date>august 26th 2009</date>
<orders>
<items><product>books</product><quantity>5</quantity><prize>100</prize></items>
63

</orders>
</customer>
<customer>
<name><last_name>AVNK</last_name><first_name>Ravi teja</first_name></name>
<date>august 25th 2009</date>
<orders>
<items><product>books</product><quantity>2</quantity><prize>1000</prize></items>
</orders>
</customer>
</Document>

Output:
64

19.Aim: XSD file

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema">

<xs:element name="student">

<xs:element name="roll no" type="xs.string"/>

<xs:element name="dept" type="xs.string"/>

<xs:element name="marks" type="xs.string"/>

</xs:element>

</xs:schema>

Output:
65

20.Aim: Jdbc application to create a table in ORACLE

Source Code:-

import java.sql.*;
public class cre
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");
int a=st.executeUpdate("create table labwork(eno number,ename
varchar2(20),esal number)");
if(a<=0)
System.out.println("Table created");
else
System.out.println("Table not created");
}
}
OUTPUT:

CMD:

C:\student program>java cre


Table created
SQL:
SQL> desc labwork;
Name Null? Type
----------------------------------------- -------- ----------------------------
ENO NUMBER
ENAME VARCHAR2(20)
ESAL NUMBER
66

21.Aim: Jdbc application to insert the values into the table

Source Code:-

import java.sql.*;
public class ins
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");
Statement st=con.createStatement();
int a=st.executeUpdate("insert into labwork values(111,'aaa',4000)");
int b=st.executeUpdate("insert into labwork values(222,'bbb',6000)");
if(a==1 && b==1)
System.out.println("Error");
else
System.out.println("rows added");
}
}
OUTPUT:

CMD:
C:\student program>java ins
Rows added
SQL:
SQL> select * from labwork;

ENO ENAME ESAL


---------- -------------------- ----------
111 aaa 4000
222 bbb 6000
67

22.Aim: Jdbc application to select all the rows and all the columns form the
table

Source Code:-

import java.sql.*;
public class sel
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from labwork");
while(rs.next())
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3));

}
}

OUTPUT:

CMD:

C:\student program>java sel


111 aaa 4000
222 bbb 6000
68

23.Aim: Jdbc application to update the table with a bonus amount of 200 for
those salaries less than 5000

Source Code:-

import java.sql.*;
public class update
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");
Statement st=con.createStatement();
int a=st.executeUpdate("update labwork set esal=esal+200 where esal<5000");
if(a>0)
System.out.println("Table Updated");
else
System.out.println("Error");
}
}
OUTPUT:

CMD:
C:\student program>java update
Table Updated
SQL:
SQL> select * from labwork;

ENO ENAME ESAL


---------- -------------------- ----------
111 aaa 4200
222 b 6000
69

24.Aim: Jdbc application to insert the values into the table through keyboard

Source Code:-

import java.sql.*;

import java.io.*;

public class ins_key


{
public static void main(String args[])throws Exception
{
int no,sal;
String name;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the no, name and Salary");
no=Integer.parseInt(br.readLine());
name=br.readLine();
sal=Integer.parseInt(br.readLine());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");
Statement st=con.createStatement();
int a=st.executeUpdate("insert into labwork values("+no+",'"+name+"',"+sal+")");
if(a<=0)
System.out.println("Error");
else
System.out.println("1 row added");
}
}
70

OUTPUT:

CMD:

C:\student program>java ins_key


Enter the no, name and Salary
333
Ccc
2000
1 row added
SQL:
SQL> select * from labwork;

ENO ENAME ESAL


---------- -------------------- ----------
111 aaa 4200
222 bbb 6000
333 c 2000
71

25.Aim: Jdbc application to select all the rows and all the columns form the table through
the key board

Source Code:-

import java.sql.*;
import java.io.*;
public class sel_key
{
public static void main(String args[])throws Exception
{
int no;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the no");
no=Integer.parseInt(br.readLine());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from labwork where eno=”+no+”");
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3));

}
}
OUTPUT:

CMD:
C:\student program>java sel_key
Enter the no
111
111 aaa 4000
72

26.Aim: Jdbc application to delete the rows from the table

Source Code:-

import java.sql.*;
import java.io.*;
public class del_key
{
public static void main(String args[])throws Exception
{
int no;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the no");
no=Integer.parseInt(br.readLine());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");
Statement st=con.createStatement();
int a=st.executeUpdate("delete from labwork where eno="+no+"");
if(a<=0)
System.out.println("Error");
else
System.out.println("Deleted");
}
}
OUTPUT:

CMD:
C:\student program>java del_key
Enter the no
111
Deleted
SQL:
SQL> select * from labwork;
73

ENO ENAME ESAL


---------- -------------------- ----------
222 bbb 6000
333 ccc 2000
74

27.Aim: Jdbc application to delete the rows from the table using command line arguments

Source Code:-

import java.sql.*;
public class del_key
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");
Statement st=con.createStatement();
int a=st.executeUpdate("delete from labwork where eno="+args[0]+"");
if(a<=0)
System.out.println("Error");
else
System.out.println("Deleted");
}
}
OUTPUT:

CMD:
C:\student program>java del_key
Enter the no
222
Deleted
SQL:
SQL> select * from labwork;

ENO ENAME ESAL


---------- -------------------- ----------
333 c 2000
75

28.Aim: Jdbc application to insert the values into the table using prepared statement

Source Code:-

import java.sql.*;
import java.io.*;
public class ins_pre
{
public static void main(String args[])throws Exception
{
int no,sal;
String name;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");

PreparedStatement pst=con.prepareStatement("insert into labwork values(?,?,?)");


BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
System.out.println("Enter the no, name and Salary");
no=Integer.parseInt(br.readLine());
name=br.readLine();
sal=Integer.parseInt(br.readLine());
pst.setInt(1,no);
pst.setString(2,name);
pst.setInt(3,sal);
int a=pst.executeUpdate();
if(a<=0)
System.out.println("Error");
else
System.out.println("1 row added");
System.out.println("Do you want to continue [Y/N]:");
String ch=br.readLine();
if(!ch.equalsIgnoreCase("y"))
break;
76

}
}
}
OUTPUT:

CMD:

C:\student program>java ins_pre


Enter the no, name and sal
444
Ddd
9000
1 row added
Do you want to continue[Y/N]:y
Enter the no, name and sal
555
Eee
3541
1 row added
Do u want to continue[Y/N]:n
SQL:
SQL> select * from labwork;

ENO ENAME ESAL


---------- -------------------- ----------
222 bbb 6000
333 ccc 2000
444 ddd 9000
555 e 3541
77

29.Aim: Jdbc application to insert the values into the table using prepared statement

Source Code:-

import java.sql.*;
import java.io.*;
public class sel_pre
{
public static void main(String args[])throws Exception
{
int no;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");

PreparedStatement pst=con.prepareStatement("select * from labwork where


eno=?");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the no");
no=Integer.parseInt(br.readLine());
pst.setInt(1,no);
ResultSet rs=pst.executeQuery();
while(rs.next())
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3));
}
}
OUTPUT:

CMD:

C:\student program>java sel_pre


Enter the no
222
222 bbb 6000
78

30.Aim: Jdbc application to delete the rows from the table using prepared statement

Source Code:-

import java.sql.*;
import java.io.*;
public class del_pre
{
public static void main(String args[])throws Exception
{
int no;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");

PreparedStatement pst=con.prepareStatement("delete from labwork where


eno=?");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the no");
no=Integer.parseInt(br.readLine());
pst.setInt(1,no);
int a=pst.executeUpdate();
if(a<=0)
System.out.println("Error");
else
System.out.println("Deleted");
}
}
OUTPUT:

CMD:
C:\student program>java del_pre
Enter the no
79

333
Deleted
SQL:
SQL> select * from labwork;

ENO ENAME ESAL


---------- -------------------- ----------
222 bbb 6000
444 ddd 9000
555 e 3541
80

31.Aim: Jdbc application to update the table using prepared statement

Source Code:-

import java.sql.*;
import java.io.*;
public class upd_pre
{
public static void main(String args[])throws Exception
{
int no;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");

PreparedStatement pst=con.prepareStatement("update labwork set esal=esal+500


where eno=?");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the no");
no=Integer.parseInt(br.readLine());
pst.setInt(1,no);
int a=pst.executeUpdate();
if(a<=0)
System.out.println("Error");
else
System.out.println("Table Updated");
}
}
81

OUTPUT:

CMD:

C:\student program>java upd_pre


Enter the no
555
Table Updated
SQL:
SQL> select * from labwork;

ENO ENAME ESAL


---------- -------------------- ----------
222 bbb 6000
444 ddd 9000
555 e 4041
82

32.Aim: Jdbc application to insert into the table using callable statement

Source Code:-

SQL> create or replace procedure profirst


2 as
3 begin
4 insert into labwork values(101,'ddd',1223);
5 end profirst;
6 /
Procedure created.

import java.sql.*;
import java.io.*;
class ins_call
{
public static void main(String args[])throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");
CallableStatement cst=con.prepareCall("{call profirst}");
cst.execute();
System.out.println("Row Added");
}
}
83

OUTPUT:

CMD:

C:\student program>java ins_call


Row Added
SQL:
SQL> select * from labwork;

ENO ENAME ESAL


---------- -------------------- ----------
222 bbb 6000
444 ddd 9000
555 eee 4041
101 d 1223
84

33.Aim: Jdbc application to update the table using callable statement

Source Code:-

SQL> create or replace procedure pro_update(no in number, sal out number)


2 as
3 begin
4 select esal into sal from labwork where no=eno;
5 update labwork set esal=sal+sal*0.5 where no=eno;
6 end pro_update;
7 /
Procedure created.

import java.sql.*;
import java.io.*;
class upd_call
{
public static void main(String args[])throws Exception
{
int no;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
no=Integer.parseInt(br.readLine());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");
CallableStatement cst=con.prepareCall("{call pro_update(?,?)}");
cst.setInt(1,no);
cst.registerOutParameter(2,Types.INTEGER);
cst.execute();
System.out.println(cst.getInt(2));
}
}
85

OUTPUT:

CMD:
C:\student program>java upd_call
Enter a number
101
1834.5
SQL:
SQL> select * from labwork;
ENO ENAME ESAL
---------- -------------------- ----------
222 bbb 6000
444 ddd 9000
555 eee 4041
101 d 1834.5
86

34.Aim: Jdbc application to delete the form the table using callable statement

Source Code:-

SQL> create or replace procedure pro_del(no in number)


2 as
3 begin
4 delete from labwork where no=eno;
5 end pro_del;
6 /
Procedure created.

import java.sql.*;
import java.io.*;
class del_call
{
public static void main(String args[])throws Exception
{
int no;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
no=Integer.parseInt(br.readLine());
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:lab","scott","tiger");
CallableStatement cst=con.prepareCall("{call pro_del(?)}");
cst.setInt(1,no);
cst.execute();
System.out.println("row deleted");
}
}
87

OUTPUT:

CMD:
C:\student program>java del_call
Enter a number
101
row deleted
SQL:
SQL> select * from labwork;

ENO ENAME ESAL


---------- -------------------- ----------
222 bbb 6000
444 ddd 9000
555 eee 4041
88

35.Aim: To Demonstrate Generic Servlet

Source Code:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class First extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)throws
IOException,ServletException
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
pw.println("<html>");
pw.println("<head>");
pw.println("<title>TOMCAT SERVER</title>");
pw.println("<body>");
pw.println("<h1>Hello</h1>");
pw.println("</body></html>");
pw.close();
}
}

Save it in Deployment folder/WEB-INF/classes.

Needed xml file is

<web-app>
<servlet>
<servlet-name>ser</servlet-name>
<servlet-class>First</servlet-class>
</servlet>
<servlet-mapping>
89

<url-pattern>/ab</url-pattern>
<servlet-name>ser</servlet-name>
</servlet-mapping>
</web-app>
Save it in Deployment folder/WEB-INF.

Output:
90

36.Aim: To Demonstrate HttpServlet

Source Code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class httpex extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
IOException,ServletException
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String nam=req.getParameter("n");
String pas=req.getParameter("p");
pw.println("<html>");
pw.println("<head>");
pw.println("<title>TOMCAT SERVER</title>");
pw.println("<body>");
pw.println(nam);
pw.println(pas);
pw.println("</body>");
pw.close();
}
}
The Needed Xml File is:
<web-app>
<servlet>
<servlet-name>ser</servlet-name>
<servlet-class>httpex</servlet-class>
91

</servlet>
<servlet-mapping>
<url-pattern>/ab</url-pattern>
<servlet-name>ser</servlet-name>
</servlet-mapping>
</web-app>
Needed HTML file is :
<html>
<head>
<title>
Http Servlet
</title>
</head>
<body>
<form method="post" action="http://127.0.0.1:8000/servlet/ab">
username <input type="text" name="n" size=30>
password <input type="password" name ="p" size=30>
<input type="submit" value="submit" name ="p1">
<input type="reset" value="cancel" name ="p2">
</form>
</body>
</html>
92

Output:
93

You might also like