Filename: 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" 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>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="Submit"></td><td><input type="reset" value="Reset"></td></tr>
</table>
</body>
</html>
Filename: 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");
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"));
int total=sub1+sub2+sub3+sub4+sub5;
float percent;
String grade="";
percent = (float)(total*100) / 500;
if(sub1<40 || sub2<40 || sub3<40 || sub4<40 || sub5<40)
grade= "FAIL";
else
{
if(percent >=70)
grade = "DISTINCTION";
else if(percent >= 60 && percent < 70)
grade = "FIRST CLASS";
else if(percent >= 50 && percent < 60)
grade = "SECOND CLASS";
else if(percent >= 40 && percent < 50)
grade = "PASS";
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:stud12");
Statement st=con.createStatement();
try
{
out.println("<h3>Data successfully inserted.</h3>");
String s="insert into stud12 values('"
+sname+"','"+regno+"','"+course+"',"+sub1+","+sub2+","+sub3+","+sub4+","
+sub5+","+total+","+percent+",'"+grade+"');";
st.executeQuery(s);
}
catch(Exception e)
{
//out.println("Insertion of data failed!");
//out.println(e);
}
%>
</body>
</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" 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>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="Submit"></td><td><input type="reset" value="Reset"></td></tr>
</table>
</body>
</html>
Filename: 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");
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"));
int total=sub1+sub2+sub3+sub4+sub5;
float percent;
String grade="";
percent = (float)(total*100) / 500;
if(sub1<40 || sub2<40 || sub3<40 || sub4<40 || sub5<40)
grade= "FAIL";
else
{
if(percent >=70)
grade = "DISTINCTION";
else if(percent >= 60 && percent < 70)
grade = "FIRST CLASS";
else if(percent >= 50 && percent < 60)
grade = "SECOND CLASS";
else if(percent >= 40 && percent < 50)
grade = "PASS";
}
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:stud12");
Statement st=con.createStatement();
try
{
out.println("<h3>Data successfully inserted.</h3>");
String s="insert into stud12 values('"
+sname+"','"+regno+"','"+course+"',"+sub1+","+sub2+","+sub3+","+sub4+","
+sub5+","+total+","+percent+",'"+grade+"');";
st.executeQuery(s);
}
catch(Exception e)
{
//out.println("Insertion of data failed!");
//out.println(e);
}
%>
</body>
</html>
No comments :
Post a Comment