Search This Blog

Thursday, 4 September 2014

15. JSP Program to Evaluate Salary Details of an Employee and Store into Database.

Filename: Employee15.jsp
<!-- 15. JSP Program to Evaluate Salary Details of an Employee and Store into Database. -->
<html>
<head>
<%@ page import="java.sql.*" %>
</head>
<body bgcolor="beige">

<%
   
    String ename="Mahesh7";
    String dept="Finance";
    String des="Manager";
    double bsal=20000;
    double ta=10;
    double da=30;
    double hra=10;
    double pf=10;
    double lic=15;
    double allowance;
    double deduction;
    double gsal;
    double netsal;

    allowance = (bsal*ta)/100 + (bsal*da)/100 + (bsal*hra)/100;
    deduction = (bsal*pf)/100 + (bsal*lic)/100;
    gsal = bsal + allowance;
    netsal = gsal - deduction;
   
    try
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       
        Connection con=DriverManager.getConnection("jdbc:odbc:sal15");
       
        Statement st=con.createStatement();
       
        String s="insert into sal15 values('"+ename+"','"+dept+"','"+des+"',"
        +bsal+","+allowance+","+gsal+","+deduction+","+netsal+");";
       
        out.println("<h3>Employee Details Stored in the Database Successfully!</h3>");
       
        st.executeQuery(s);
   
    }
    catch(Exception e)
    {
        //out.println(e);
    }

%>

</body>
</html>

14. JSP Program to Generate Marks Sheets of all the Students from the Database.

Filename: Stud14.jsp
<!-- 14. JSP Program to Generate Marks Sheets of all the Students from the Database. -->
<html>
<head>
<title>Student Information</title>
<%@page import="java.sql.*,java.util.*"%>
</head>
<body>
<CENTER><h2><font color="blue" >Marks Sheets of all the Students</font></h2></CENTER>

<%
    String sname=request.getParameter("sname");

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:stud14");
    Statement st=con.createStatement();
   
    ResultSet rs=st.executeQuery("select * from stud14");
   
    while(rs.next())
    {
%>
    <CENTER>
    <table border=5 bgcolor="orange" height=600 width=400 >
    <caption><h3><font color="blue" >Marks Sheet</font></h3></caption>
    <tr><td>Name</td><td><%=rs.getString("sname")%></td></tr>
    <tr><td>Register Number</td><td><%=rs.getString("regno")%></td></tr>
    <tr><td>Course</td><td><%=rs.getString("course")%></td></tr>
    <tr><td>Subject1</td><td><%=rs.getString("sub1")%></td></tr>
    <tr><td>Subject2</td><td><%=rs.getString("sub2")%></td></tr>
    <tr><td>Subject3</td><td><%=rs.getString("sub3")%></td></tr>
    <tr><td>Subject4</td><td><%=rs.getString("sub4")%></td></tr>
    <tr><td>Subject5</td><td><%=rs.getString("sub5")%></td></tr>
    <tr><td>Total</td><td><%=rs.getString("total")%></td></tr>

    <tr><td>Percent</td><td><%=rs.getString("percent")%></td></tr>
    <tr><td>Grade</td><td><%=rs.getString("grade")%></td></tr>
    </table>
    </CENTER>
    <br>

<%
    }
   

    rs.close();
    st.close();
    con.close();

%>

</body>
</html>

13. HTML and JSP Program to Retrieve Student Information from the Database.

Filename:Stud13.html
<!-- 13. HTML Program to accept Student name -->
<html>
 <head>

 <title>Student Marks Sheet</title>
 </head>
 <body>
 <h3>Enter the Name of Student:<h3>
 <form action="Stud13.jsp" method="POST" >

    <input type="text" name="sname" autofocus><br><br>
    <input type="submit" value="Get Details">

 
 </body>
</html>

Filename:Stud13.jsp
<!-- 13. JSP Program to Retrieve Student Information from the Database. -->
<html>
<head>
<title>Student Information</title>
<%@page import="java.sql.*,java.util.*"%>
</head>
<body>
<%
    String sname=request.getParameter("sname");

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:stud13");
    Statement st=con.createStatement();
   
    ResultSet rs=st.executeQuery("select * from stud13 where sname='"+sname+"'");
   
    while(rs.next())
    {
%>
    <CENTER>
    <table border=5 bgcolor="orange" height=600 width=400 >
    <caption><h2><font color="blue" >Marks Sheet</font></h2></caption>
    <tr><td>Name</td><td><%=rs.getString("sname")%></td></tr>
    <tr><td>Register Number</td><td><%=rs.getString("regno")%></td></tr>
    <tr><td>Course</td><td><%=rs.getString("course")%></td></tr>
    <tr><td>Subject1</td><td><%=rs.getString("sub1")%></td></tr>
    <tr><td>Subject2</td><td><%=rs.getString("sub2")%></td></tr>
    <tr><td>Subject3</td><td><%=rs.getString("sub3")%></td></tr>
    <tr><td>Subject4</td><td><%=rs.getString("sub4")%></td></tr>
    <tr><td>Subject5</td><td><%=rs.getString("sub5")%></td></tr>
    <tr><td>Total</td><td><%=rs.getString("total")%></td></tr>

    <tr><td>Percent</td><td><%=rs.getString("percent")%></td></tr>
    <tr><td>Grade</td><td><%=rs.getString("grade")%></td></tr>
    </table>
    </CENTER>

<%
    }
   

    rs.close();
    st.close();
    con.close();

%>

</body>
</html>

12. HTML and JSP Program to Read Student Information and Store into Database.

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>
 


11. HTML and JSP Program to Read Student Information and Store into Database.

Filename: Stud11.html
<!-- 11. Program to read student information and store into database -->
<html>
 <head>

 <title>Student Information</title>
 </head>
 <body>
 <h3>Enter Student Details:<h3>
 <form action="Stud11.jsp" method="POST" >
 <table >
 <tr><td>Student 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>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><td><input type="reset" value="Reset"></td></tr>
 </table>
 
 </body>
</html>


Filename:Stud11.jsp
<!-- 11. 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 college=request.getParameter("college");
    String city=request.getParameter("city");
    String phone=request.getParameter("phone");
    int len=phone.length();
   
   
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:stud1");
    Statement st=con.createStatement();
    if(len<=10)
    {
        try
        {
            out.println("Data successfully inserted.");
            String s="insert into Student values('"
            +sname+"','"+regno+"','"+course+"','"+college+"','"+city+"','"+phone+"');";
                st.executeQuery(s);
       
        }
        catch(Exception e)
        {
            //out.println("Insertion of data failed!");
            //out.println(e);
        }
    }
    else
    {
        out.println("Invalid Phone Number");
    }

%>

FREE Hit Counters