4. Write a multilayered JSP
application to accept and store student information. Accept student name, register number,
course, combination, semester, marks obtained in five subjects as input through a
proper user interface page. Design course, combination and semester as combo boxes. Store
the accepted details in the MS Access table.
Code
for Stud12.html:
<!-- 12. Program to read
student info. and store into database -->
<html>
<head>
<title>Student Information</title>
</head>
<body>
<h3>Enter Student Details:</h3>
<form action="Stud12.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> <select name="course">
<option >BCA</option>
<option >BSc</option>
<option >BA</option>
</select> </td></tr>
<tr><td>Combination:</td><td> <select name="comb">
<option >Computer Applications</option>
<option >PMCs</option>
<option >EMCs</option>
<option >HSP</option>
<option >HEK</option>
</select> </td></tr>
<tr><td>Semester:</td><td> <select name="sem">
<option >I</option>
<option >II</option>
<option >III</option>
<option >IV</option>
<option >V</option>
<option >VI</option>
</select> </td></tr>
<tr><td>Sub1:</td><td><input type="text"
name="sub1"></td></tr>
<tr><td>Sub2:</td><td><input type="text"
name="sub2"></td></tr>
<tr><td>Sub3:</td><td><input type="text"
name="sub3"></td></tr>
<tr><td>Sub4:</td><td><input type="text"
name="sub4"></td></tr>
<tr><td>Sub5:</td><td><input type="text"
name="sub5"></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 Stud12.jsp:
<!-- 12. JSP Program to
Store Student Information in 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 comb=request.getParameter("comb");
String sem=request.getParameter("sem");
int
sub1=Integer.parseInt(request.getParameter("sub1"));
int
sub2=Integer.parseInt(request.getParameter("sub2"));
int
sub3=Integer.parseInt(request.getParameter("sub3"));
int
sub4=Integer.parseInt(request.getParameter("sub4"));
int
sub5=Integer.parseInt(request.getParameter("sub5"));
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:stud12");
Statement st=con.createStatement();
try
{
out.println("<h3>Data
Saved Successfully!</h3>");
String s="insert into stud12 values('"+sname+"','"+regno
+"','"+course+"','"+comb+"','"+sem+"',"+sub1
+","+sub2+","+sub3+","+sub4+","+sub5+");";
st.executeQuery(s);
}
catch(Exception e)
{
//out.println("Insertion of data
failed!");
//out.println(e);
}
%>
</body>
</html>
Hey Nice Blog!! Thanks For Sharing!!!Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging!
ReplyDeletebest java training in coimbatore
php training in coimbatore
best php training institutes in coimbatore