Search This Blog

Thursday, 4 September 2014

23. HTML and JSP Program to Evaluate and Store Student Information in the Database.

Filename: Stud23.html

<!-- 23. Program to read student info. and store into database -->
<html>
 <head>

 <title>Student Information</title>
 </head>
 <body>
 <h3>Enter Student Details:<h3>
 <form action="Stud23.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>    <select name="course">
                            <option value="BCA">BCA</option>
                            <option value="BSc">BSc</option>
                            <option value="BA">BA</option>
                            </select> </td></tr>

 <tr><td>Combination:</td><td>    <select name="comb">
                            <option value="Computer Applications">Computer Applications</option>
                            <option value="PMCs">PMCs</option>
                            <option value="EMCs">EMCs</option>
                            <option value="HSP">HSP</option>
                            <option value="HEK">HEK</option>
                            </select> </td></tr>
 <tr><td>Semester:</td><td>    <select name="sem">
                            <option value="I">I</option>
                            <option value="II">II</option>
                            <option value="III">III</option>
                            <option value="IV">IV</option>
                            <option value="V">V</option>
                            <option value="VI">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>
 </body>
</html>

Filename: Stud23.jsp
<!-- 23. JSP Program to Evaluate and 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"));
   
    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:stud23");
    Statement st=con.createStatement();
    try
    {
        out.println("<h3>Data Saved Successfully!</h3>");
        String s="insert into stud23 values('"+sname+"','"+regno
            +"','"+course+"','"+comb+"','"+sem+"',"+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

FREE Hit Counters