Anda di halaman 1dari 34

VIGNANS UNIVERSITY, VADLAMUDI

Web Technologies
Class: CSE-

Regd.No:

Page No:

LAB CYCLE 1

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

PROGRAM NO: 1

DATE:

AIM:
1. Create an HTML page having Four frames named
a. Top
b. Center
c. Bottom
d. Left
The Top frame should contain company logo and title. The bottom frame should contain
copy right information. The Left frame should contain various links like Home, Products,
Services, Branches, About us, etc. When we click on those links, the contents should
come in to Center Frame.
Frame.html
<html>
<head>
<title> Andhra Pradesh </title>
</head>
<frameset rows="20%, 70%, *">
<frame src= "title.html" name="title" />
<frameset cols="20%, *">
<frame src="link.html" name="links"/>
<frame src="desc.html" name="desc"/>
</frameset>
<frame src="rights.html" name="rights"/>
</frameset>
</html>
Title.html
<html>
<head>
<title> Andhra Pradesh</title>
</head>
<body bgcolor="orange" >
<center>
<font color= "red"><h1 > Andhra Pradesh</h1></font>
<font color= "green"><h3>The Sunrise State</h3></font>
</center>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

</body>
</html>
Link.html
<html>
<head>
<title> VIGNAN</title>
</head>
<body bgcolor=lightgreen alink="blue" >
<center> <br><br><br><br><br><br>
<A href="aboutus.html" target="desc"> About AP</A><br>
<A href="districts.html" target="desc">District </A><br>
<A href="tourism.html" target="desc">Tourist places</A><br>
</center>
</body>
</html>
Desc.html
<html>
<head>
<title>Andhra Pradesh</title>
</head>
<body >
<img src="andhra-1.jpg" width="100%">
</body>
</html>
Aboutus.html
<html>
<head>
<title> About Andhra Pradesh</title>
</head>
<body bgcolor="yellow">
<p>Andhra Pradesh is one of the 29 states of India, situated on the southeastern coast of the
country. The state is the eighth largest state in India covering an area of 160,205 km2 (61,855 sq
mi).[3] As per 2011 census of India, the state is tenth largest by population with 49,386,799
inhabitants. On 2 June 2014, the north-western portion of the state was bifurcated to form a new
state of Telangana.</p>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

</body>
</html>

Districts.html
<html>
<head>
<title> district </title>
</head>
<body bgcolor="yellow">
<br>Anantapur<br>
Chittor<br>
East Godavari<br>
Guntur<br>
Cuddapah<br>
Krishna<br>
Kurnool<br>
Prakasam<br>
Nellore<br>
Srikakulam<br>
Visakhapatnam<br>
Vizianagaram<br>
West Godavari<br>
</body>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

</html>

Tourism.html
<html>
<head>
<title>tourism</title>
</head>
<body>
<img src="t.jpeg" width="100%" height="100%"/>
</body>
</html>
Right.html
<html>
<head>
<title>Andhra Pradesh</title>
</head>
<body bgcolor=lightblue >
<center>All rights reserved@Andhra Pradesh Goverment </center>
</body>
</html>
Output:-

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

PROGRAM NO: 2

DATE:

AIM:
Create a HTML document to demonstrate Form Elements that includes Form, input-text,
password, radio, checkbox, hidden, button, submit, reset, label, textarea, select, option,
file upload.
<html>
<head>
<title>ONLINE APPLICATION FORM </title>
</head>
<body bgcolor=lightgreen>
<form>
<label for="Name">Name
<input type="name" name="Name" ><br>
Password<input type="password" name="password" ><br>
GENDER<BR>
MALE
<input type="radio" name="gen"/>
FEMALE <input type="radio" name="gen"/><br><br>
Qualification<br>
SSC<input type="checkbox" name="SSC><br>
Inter<input type="checkbox" name="Inter" ><br>
B.Tech<input type="checkbox" name="B.tech><br>
M.Tech<input type="checkbox" name="M.tech"><br>
Select state
<select>
<option value="Andhra Pradesh">Andhra Pradesh</option>
<option value="Tamilnadu">Tamilnadu</option>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

<option value="Kerala">Kerala</option>
<option value="Chattisgarh">Chattisgarh</option>
</select><br>
file upload<input type="file" name="myfile" ><br>
<input type="hidden" value="INDIAN" >
<input type="submit" value="submit" >
<input type="reset" value="reset" >
<input type="button" value="cancel" >
</form>
</body>
</html>

OUTPUT:

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

PROGRAM NO: 3

DATE:

AIM:
Design an HTML having a text box and four buttons viz Factorial, Fibonacci, Prime, and
Palindrome. When a button is pressed an appropriate javascript function should be called to
display
a. Factorial of that number
b. Fibonacci series up to that number
c. Prime numbers up to that number
d. Is it palindrome or not
a)Factorial of that number
<HTML>
<BODY>
<script type="text/javascript">
document.write("<h2>Table of Factorials</h2>");
for(i = 1, fact = 1; i < 10; i++, fact *= i)
{
document.write(i + "! = " + fact);
document.write("<br>");
}
</script>
</BODY>
</HTML>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

OUTPUT:

b) Fibonacci series up to that number


<html>
<body>
<script type="text/javascript">
var a=0,b=1,c;
document.write("Fibonacci");
while (b<=100)
{
document.write(c);
document.write("<br>");
c=a+b;
a=b;
b=c;
}
</script>
</body>
</html>

OUTPUT:

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

c). Prime numbers up to that number


<html>
<body>
<script type="text/javascript">
function checkPalindrome()
{
var revStr = "";
var str = document.getElementById("str").value;
var i = str.length;
for(var j=i; j>=0; j--)
{
revStr = revStr+str.charAt(j);
}
if(str == revStr)
{
alert(str+" -is Palindrome");
}
else
{
alert(str+" -is not a Palindrome");
}
}

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

</script>
<form >
Enter a String/Number: <input type="text" id="str" name="string" /><br />
<input type="submit" value="Check" onclick="checkPalindrome();"/>
</form>
</body>
</html>
OUTPUT:

d. Is it palindrome or not
<html>
<head>
<script language="javascript">
var a=prompt("enter a value");
alert(a);
var c=0;
for(var i=2;i<a;i++)
{
if(a%i==0)
{
c=i;
}
}
if(c==0)
{
alert("Given number is Prime");
}
else
{
alert("Given number is not Prime");
}
</script>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

</head>
<body>
</body>
</html>
OUTPUT:

PROGRAM NO: 4

DATE:

AIM:
Write java script programs to demonstrate
a. Math Object with at least five methods.
b. String Object with at least five methods.
c. Date Object with at least five methods.
d. Array Object with at least five methods
a. Math Object with at least five methods
<html>
<head>
<title>Java Script Math Object</title>
</head>
<body>
<script type="text/javascript">
document.write("Square root of 25 is"+Math.sqrt(25)+"<br>");
document.write(" 2 power 5 is is "+Math.pow(2,5)+"<br>");
document.write("Minimum value among 25 and 35 is"+Math.min(25,35)+"<br>");
document.write("Ceil of 1.11 is "+Math.ceil(1.11)+"<br>");
document.write("Floor of 1.11 is "+Math.floor(1.11)+"<br>");

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

document.write("Maximum value among 25 and 300 is "+Math.max(25,300)+"<br>");


document.write("Value of sin 0.5 "+Math.sin(0.5)+"<br>");
document.write("Value of cos 0 "+Math.cos(0)+"<br>");
document.write("Value of tan 60 "+Math.tan(60)+"<br>");
</script>
</body>
</html>
OUTPUT:

b.String Object with at least five methods


<html>
<head>
<title>JavaScript String String Object</title>
</head>
<body>
<script type="text/javascript">
var str1 = new String( "Today" );
var str2 = new String( "WT Lab" );
document.write(str1);
document.writeln("<br> ");
document.write(str2);
document.writeln("<br> ");
document.writeln("str1.charAt(3) is:" +str1.charAt(3));
document.writeln("<br> ");
document.writeln("str1.charAt(3) is:" +str1.charCodeAt(3));
document.writeln("<br> ");
document.writeln(str1.toString( ));
document.writeln("<br> ");
document.writeln("Lower to Upper = "+str2.toUpperCase( ));

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

document.writeln("<br> ");
document.write("(1,3):" +str1.substring(1,3));
document.writeln("<br> ");
document.write("Concatation ="+str1.concat(str2));
document.writeln("<br> ");
document.write(str2);
</script>
</body>
</html>

OUTPUT:

c. Date Object with at least five methods


<html>
<head>
<title>JavaScript Date Objects</title>
</head>
<body>
<script type="text/javascript">
var d=new Date();
document.write("today date is"+d.getDate());
document.writeln("<br> ");
document.write("today day is"+d.getDay());
document.writeln("<br> ");
document.write("hours="+d.getHours());
document.writeln("<br> ");
document.write("Minutes="+d.getMinutes());
document.writeln("<br> ");
document.write("MilliSeconds="+d.getMilliseconds() );
</script>
</body>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

</html>

OUTPUT:

d. Array Object with atleast five methods


<html>
<head>
<title>JavaScript Array Object</title>
</head>
<body>
<script type="text/javascript">
var arr = new Array("orange", "mango", "banana", "sugar");
var numeric = [7, 2, 5, 3];
var sorted = arr.sort();
document.write("Returned string is : " + sorted );
document.write("<br>");
var ar = numeric.reverse();
document.write("Reversed array is : " + ar );
document.write("<br>");

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

document.write("Concat is: " + arr.concat(numeric));


document.write("<br>");
var elem = numeric.pop();
document.write("Top Popped element is : " + elem );
document.write("<br>");
var element = [105, 1, 2, 3].shift();
document.write("Removed element is : " + element );
</script>
</body>
</html>
OUTPUT:

PROGRAM NO: 5

DATE:

AIM:
Write a java script program to display message on OnBlur and OnFocus events.
<html>
<head>
</head>
<body>
name:<input type="text" id="name" onblur="myfunction()"
onfocus="myfunction()">
<script>
function myfunction()
{
var x=document.getElementById("name");
x.value=x.value.toUpperCase();
x.style.background="blue";

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

}
</script>
</body>
</html>
OUTPUT:-

PROGRAM NO: 6

DATE:

AIM:
Create an XML document where CSEBooks is the root tag,it consists of 5 books named
as(book1, book2, book3, book4, book5) whose copies of books are 10 and provide the
child tag such as author,title,pages,price for all books
<?xml version="1.0" encoding="UTF-08" ?>
<!DOCTYPE cse SYSTEM "1.dtd">
<cse>
<book1>
<author>bates</author>
<title>wt</title>
<pages>300</pages>
<price>500</price>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

</book1>
<book2>
<author>bates</author>
<title>wt</title>
<pages>300</pages>
<price>500</price>
</book2>
<book3>
<author>bates</author>
<title>wt</title>
<pages>300</pages>
<price>500</price>
</book3>
<book4>
<author>bates</author>
<title>wt</title>
<pages>300</pages>
<price>500</price>
</book4>
<book5>
<author>bates</author>
<title>wt</title>
<pages>300</pages>
<price>500</price>
</book5>
</cse>

1.dtd:
<!ELEMENT cse(book1+,book2+,book3+,book4+,book5+)>
<!ELEMENT book1(author,title,pages,price)>
<!ELEMENT author(#PCDATA)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT pages(#PCDATA)>
<!ELEMENT price(#PCDATA)>
<!ELEMENT book2(author,title,pages,price)>
<!ELEMENT author(#PCDATA)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT pages(#PCDATA)>
<!ELEMENT price(#PCDATA)>
<!ELEMENT book3(author,title,pages,price)>
<!ELEMENT author(#PCDATA)>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

<!ELEMENT title(#PCDATA)>
<!ELEMENT pages(#PCDATA)>
<!ELEMENT price(#PCDATA)>
<!ELEMENT book4(author,title,pages,price)>
<!ELEMENT author(#PCDATA)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT pages(#PCDATA)>
<!ELEMENT price(#PCDATA)>
<!ELEMENT book5(author,title,pages,price)>
<!ELEMENT author(#PCDATA)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT pages(#PCDATA)>
<!ELEMENT price(#PCDATA)>

OUTPUT:

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

PROGRAM NO: 6

DATE:

AIM:
For the above program, provide an associate DTD.
<!ELEMENT cse(book1+,book2+,book3+,book4+,book5+)>
<!ELEMENT book1(author,title,pages,price)>
<!ELEMENT author(#PCDATA)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT pages(#PCDATA)>
<!ELEMENT price(#PCDATA)>
<!ELEMENT book2(author,title,pages,price)>
<!ELEMENT author(#PCDATA)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT pages(#PCDATA)>
<!ELEMENT price(#PCDATA)>
<!ELEMENT book3(author,title,pages,price)>
<!ELEMENT author(#PCDATA)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT pages(#PCDATA)>
<!ELEMENT price(#PCDATA)>
<!ELEMENT book4(author,title,pages,price)>
<!ELEMENT author(#PCDATA)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT pages(#PCDATA)>
<!ELEMENT price(#PCDATA)>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

<!ELEMENT book5(author,title,pages,price)>
<!ELEMENT author(#PCDATA)>
<!ELEMENT title(#PCDATA)>
<!ELEMENT pages(#PCDATA)>
<!ELEMENT price(#PCDATA)>

PROGRAM NO: 7

DATE:

AIM:
Create an XML document where automobiles is the root tag, it consists of 5 vehicles
named as (vehicle1, vehicle2, vehicle3, vehicle4,vehicle5) and use attributes type, model,
engine no, color, cc.
<?xml version="1.0" encoding="UTF-8"?>
<automobiles xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="2.xsd">
<vehicle1>
<type>bike</type>
<model>2016</model>
<color>pink</color>
<engineno>1234</engineno>
<cc>250</cc>
</vehicle1>
<vehicle2>
<type>car</type>
<model>2015</model>
<color>white</color>
<engineno>9999</engineno>
<cc>359</cc>
</vehicle2>
<vehicle3>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

<type>scooty</type>
<model>2014</model>
<color>black</color>
<engineno>999</engineno>
<cc>159</cc>
</vehicle3>
<vehicle4>
<type>bus</type>
<model>2010</model>
<color>green</color>
<engineno>99</engineno>
<cc>150</cc>
</vehicle4>
<vehicle5>
<type>lorry</type>
<model>2000</model>
<color>red</color>
<engineno>9</engineno>
<cc>100</cc>
</vehicle5>
</automobiles>
1.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="automobile">
<xsd:ComplexType>
<xsd:sequence>
<xsd:element name="vehicle1">
<xsd:ComplexType>
<xsd:sequence>
<xsd:element name="type" type="xsd:string">
<xsd:element name="model" type="xsd:string">
<xsd:element name="color" type="xsd:string">
<xsd:element name="engineno" type="xsd:string">
<xsd:element name="cc" type="xsd:string">
</xsd:sequence>
</xsd:ComplexType>
</xsd:element>
<xsd:element name="vehicle2">
<xsd:ComplexType>
<xsd:sequence>
<xsd:element name="type" type="xsd:string">
<xsd:element name="model" type="xsd:string">
<xsd:element name="color" type="xsd:string">
<xsd:element name="engineno" type="xsd:string">

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

<xsd:element name="cc" type="xsd:string">


</xsd:sequence>
</xsd:ComplexType>
</xsd:element>
<xsd:element name="vehicle3">
<xsd:ComplexType>
<xsd:sequence>
<xsd:element name="type" type="xsd:string">
<xsd:element name="model" type="xsd:string">
<xsd:element name="color" type="xsd:string">
<xsd:element name="engineno" type="xsd:string">
<xsd:element name="cc" type="xsd:string">
</xsd:sequence>
</xsd:ComplexType>
</xsd:element>

<xsd:element name="vehicle4">
<xsd:ComplexType>
<xsd:sequence>
<xsd:element name="type" type="xsd:string">
<xsd:element name="model" type="xsd:string">
<xsd:element name="color" type="xsd:string">
<xsd:element name="engineno" type="xsd:string">
<xsd:element name="cc" type="xsd:string">
</xsd:sequence>
</xsd:ComplexType>
</xsd:element>
</xsd:sequence>
</xsd:ComplexType>
</xsd:element>
</xsd:schema>
OUTPUT:

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

PROGRAM NO: 8

DATE:

AIM:
For the above program, provide an associated Schema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="automobile">
<xsd:ComplexType>
<xsd:sequence>
<xsd:element name="vehicle1">
<xsd:ComplexType>
<xsd:sequence>
<xsd:element name="type" type="xsd:string">
<xsd:element name="model" type="xsd:string">
<xsd:element name="color" type="xsd:string">
<xsd:element name="engineno" type="xsd:string">

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

<xsd:element name="cc" type="xsd:string">


</xsd:sequence>
</xsd:ComplexType>
</xsd:element>
<xsd:element name="vehicle2">
<xsd:ComplexType>
<xsd:sequence>
<xsd:element name="type" type="xsd:string">
<xsd:element name="model" type="xsd:string">
<xsd:element name="color" type="xsd:string">
<xsd:element name="engineno" type="xsd:string">
<xsd:element name="cc" type="xsd:string">
</xsd:sequence>
</xsd:ComplexType>
</xsd:element>
<xsd:element name="vehicle3">
<xsd:ComplexType>
<xsd:sequence>
<xsd:element name="type" type="xsd:string">
<xsd:element name="model" type="xsd:string">
<xsd:element name="color" type="xsd:string">
<xsd:element name="engineno" type="xsd:string">
<xsd:element name="cc" type="xsd:string">
</xsd:sequence>
</xsd:ComplexType>
</xsd:element>

<xsd:element name="vehicle4">
<xsd:ComplexType>
<xsd:sequence>
<xsd:element name="type" type="xsd:string">
<xsd:element name="model" type="xsd:string">
<xsd:element name="color" type="xsd:string">
<xsd:element name="engineno" type="xsd:string">
<xsd:element name="cc" type="xsd:string">
</xsd:sequence>
</xsd:ComplexType>
</xsd:element>
</xsd:sequence>
</xsd:ComplexType>
</xsd:element>
</xsd:schema>

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

LAB CYCLE 2

1. Write a JDBC program to create table in MYSQL database.


import java.sql.*;
import java.io.*;
public class JDBC_CR_Table
{
static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
static final String DB_URL="jdbc:mysql://localhost:3306/EMPLOYEE";
static final String USER="root";
static final String PASS="";
public static void main(String[] args)
{
Connection con=null;

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

Statement stmt=null;
Try
{
Class.forName(JDBC_DRIVER);
System.out.println("Connecting to DB");
con=DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println("Connected");
System.out.println("creating table");
stmt=con.createStatement();
String sql="create table student(id INTEGER,name VARCHAR(20),sal INTEGER)";
stmt.executeUpdate(sql);
stmt.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

output:

2. Write a JDBC program to insert data into table in MYSQL database.


import java.sql.*;
import java.io.*;
public class JDBC_INS_Table
{
static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
static final String DB_URL="jdbc:mysql://localhost:3306/EMPLOYEE";
static final String USER="root";
static final String PASS="";
public static void main(String[] args)
{
Connection con=null;

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

Statement stmt=null;
Try
{
Class.forName(JDBC_DRIVER);
System.out.println("Connecting to DB");
con=DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println("Connected");
System.out.println("creating table");
stmt=con.createStatement();
String sql="insert into student values(6,'naga',2000)";
stmt.executeUpdate(sql);
System.out.println("inserted data");
stmt.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

output:

3. Write a JDBC program to retrieve data from table in MYSQL database.


import java.sql.*;
import java.io.*;
public class JDBC_RET_Table
{
static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
static final String DB_URL="jdbc:mysql://localhost:3306/EMPLOYEE";
static final String USER="root";
static final String PASS="";
public static void main(String[] args)
{

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Regd.No:

Class: CSE-

Page No:

Connection con=null;
Statement stmt=null;
Try
{
Class.forName(JDBC_DRIVER);
System.out.println("Connecting to DB");
con=DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println("Connected");
System.out.println("creating table");
stmt=con.createStatement();
String sql="select * from student";
ResultSetrs=stmt.executeQuery(sql);
System.out.println(" id name sal" );
while(rs.next())
{
int id=rs.getInt("id");
String name=rs.getString("name");
intsal=rs.getInt("sal");
System.out.println(id+" "+name+" "+sal );
}
stmt.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

output:

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

4. Write a JDBC programto update data in a MYSQL database table.

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

import java.sql.*;
import java.io.*;
public class JDBC_UPD_Table
{
static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
static final String DB_URL="jdbc:mysql://localhost:3306/EMPLOYEE";
static final String USER="root";
static final String PASS="";
public static void main(String[] args)
{
Connection con=null;
Statement stmt=null;
Try
{
Class.forName(JDBC_DRIVER);
System.out.println("Connecting to DB");
con=DriverManager.getConnection(DB_URL,USER,PASS);
System.out.println("Connected");
System.out.println("creating table");
stmt=con.createStatement();
System.out.println("table updating");
String sql="update student set name='hvr' where id=6";
stmt.executeUpdate(sql);
stmt.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

output:

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

5.Display welcome text by extending http servlet.


Index.html:
<html>
<head>
</head>
<body>
<form method="get" action="Register">
USERNAME:<input type="text" name="uname" size="15" maxlength="25"/><br>
PASSWORD:<input type="text" name="pword" size="15" maxlength="25"/><br>
MOBILENO:<input type="text" name="mno" size="15" maxlength="25"/><br>
EMAIL<input type="text" name="em" size="25"/></br>
<input type="submit" value="register"/><br>
</form>
</body>
</html>
Register.java:
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.*;
import java.io.*;
public class Register extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("welcome");
}
}

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

VIGNANS UNIVERSITY, VADLAMUDI


Web Technologies
Class: CSE-

Regd.No:

Page No:

web.xml:
<web-app>
<servlet>
<servlet-name>RS</servlet-name>
<servlet-class>Register</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RS</servlet-name>
<url-pattern>/Register</url-pattern>
</servlet-mapping>
</web-app>

output:

VIGNANS FOUNDATION FOR SCIENCE,TECHNOLOGY AND RESEARCH

Anda mungkin juga menyukai