BCA

WEB PROGRAMMING LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12 PROGRAM 13 PROGRAM 14 PROGRAM 15 . . .

9. Write a JSP application to read the details of a student and store the same on to the ms access database.
OUTPUT: Student Information

Enter Student Details:

Student Database:
Register Number:
Course:
College:
City:
Phone:

PAGE 1: program9startpage.html

 
 

	
<html>
<head>
<title>Student Information</title>
</head>
<body>
<h3>Enter Student Details:</h3>
<form action="program9endpage.jsp" method="POST">
<table>
<tr><td>Student Database:</td><td><input type="text" name="sname" autofocus></td></tr>
<tr><td>Register Number:</td><td><input type="text" name="regno" ></td></tr>
<tr><td>Course:</td><td><input type="text" name="course"></td></tr>
<tr><td>College:</td><td><input type="text" name="college"></td></tr>
<tr><td>City:</td><td><input type="text" name="city"></td></tr>
<tr><td>Phone:</td><td><input type="text" name="phone"></td></tr>
<tr><td><input type="submit" value="Store in Database"></td></tr>
<tr><td><input type="reset" value="Reset"></td></tr>
</table>
</form>
</body>
</html>


PAGE 1: program9endpage.jsp

 

<html>
<head>
    <style>
    table, th, td {
  border: 1px solid black;
}
</style>
<title>Student Information</title>
<%@ page import="java.sql.*,java.util.*"%>
</head>
<body>
<h6>STUDENT INFORMATION IS STORED SUCCESSFULLY</h6>
<%
String sname=request.getParameter("sname");
String regno=request.getParameter("regno");
String course=request.getParameter("course");
String college=request.getParameter("college");
String city=request.getParameter("city");
String phone=request.getParameter("phone");

out.print("<table>");
out.println("<tr><td>ID</td><td>"+regno+"</td></tr>");
 out.println("<tr><td>NAME </td><td>"+sname+"</td></tr>");
 out.println("<tr><td>college</td><td>"+college+"</td></tr>");
 out.println("<tr><td>course </td><td>"+course+"</td></tr>");
 
out.print("</table>");
try
{

int len=phone.length();


        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	    Connection con=DriverManager.getConnection("jdbc:odbc:db2");
		Statement st=con.createStatement();
		
		if(len==10)
		{
			try
			{
		out.println("<h1>Data Successfully inserted.<h1>");
		
String s="insert into Table1 values('"+regno+"','"+sname+"','"+course+"','"+college+"','"+city+"','"+phone+"');";
		st.executeQuery(s);
			}
		catch(Exception e){}
		}
		else
			out.println("<h3>invalid phone number!!!!!!<h3>");
			}
catch(Exception e)
{
	out.println(e);
}
		%>
		</body>
		</html>