1. Write a JSP application to
read the details of a student and store the same on to the MS Access database.
Code for HTML Program:
<!-- HTML
Program to read student info.-->
<head>
<title>Student Information</title>
</head>
<body>
<h3>Enter Student Details:</h3>
<form action="Stud9.jsp" method="POST" >
<table >
<tr><td>Name:</td><td><input type="text" name="sname" ></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><input type="submit" value="Save in Database" ></td>
<td><input type="reset" value="Reset" ></td></tr>
</table>
</form>
</body>
</html>
Code for JSP Program:
<!--JSP Program to store Student Information in
to the Database.-->
<html><head>
<title>Student Information</title>
<%@ page import="java.sql.*, java.util.*"%>
</head>
<body>
<%
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");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:stud9");
Statement st=con.createStatement();
try
{
out.println("<h3>Data Saved Successfully!</h3>");
String s="insert into Stud9 values('"+sname+"','"+regno
+"','"+course+"','"+college+"','"+city+"');";
st.executeQuery(s);
}
catch(Exception e)
{
//out.println("Insertion of data failed!");
//out.println(e);
}
%>
</body>
</html>
No comments :
Post a Comment