Search This Blog

Wednesday, 11 February 2015

1. JSP Program to create table in Oracle 10g, insert values in it and display the same.

<!-- JSP Program to create table in Oracle 10g, insert values in it and display the same. -->
<html>
<head>
<title>Student Information</title>
<%@page import="java.sql.*,java.util.*"%>
</head>
<body>


<%
    try
    { 
                //step1 load the driver class 
            Class.forName("oracle.jdbc.driver.OracleDriver"); 
     
                //step2 create  the connection object 
            Connection con=DriverManager.getConnection( 
            "jdbc:oracle:thin:@localhost:1521:xe","system","tiger"); 
     
                //step3 create the statemnt object 
            Statement stmt=con.createStatement(); 
            //stmt.executeUpdate("create table mytable1(NAME varchar2(20),DOB varchar2(15))");
            System.out.println("Table created successfully!");
   
            stmt.executeQuery("insert into mytable1 values('Vijay','10-SEP-2000')");
                //step4 execute query 
            ResultSet rs=stmt.executeQuery("select * from mytable1"); 
            while(rs.next()) 
            {
%>

                <CENTER>
                    <table border=5 bgcolor="orange" height=50 width=100 >
                        <caption><h3><font color="blue" >MyTable</font></h3></caption>
                            <tr><td><%=rs.getString("NAME")%></td><td><%=rs.getString("DOB")%></td></tr>
                    </table>
                </CENTER>
<%
            }
           
     
                //step5 close the connection object 
            con.close(); 
     
        }catch(Exception e){ System.out.println(e);}
   
%>

</body>
</html>

Thursday, 4 September 2014

24. HTML and JSP Program to Evaluate Salary Details of an Employee and Store in Database

Filename: Employee24.html
<!-- 24. Program to accept Employee Details. -->
<html>
 <head>

 <title>Employee Details</title>
 </head>
 <body>
 <h3>Enter Employee Details:<h3>
 <form action="emp24.jsp" method="POST" >
 <table >
 <tr><td>Employee Name:</td><td><input type="text" name="ename" autofocus></td></tr>
 <tr><td>Employee ID:</td><td><input type="text" name="empid"></td></tr>
 <tr><td>Department:</td><td><input type="text" name="dept"></td></tr>
 <tr><td>Designation:</td><td><input type="text" name="des"></td></tr>
 <tr><td>Basic Salary:</td><td><input type="text" name="bsal"></td></tr>
 <tr><td>TA(%):</td><td><input type="text" name="ta"></td></tr>
 <tr><td>DA(%):</td><td><input type="text" name="da"></td></tr>
 <tr><td>HRA(%):</td><td><input type="text" name="hra"></td></tr>
 <tr><td>PF(%):</td><td><input type="text" name="pf"></td></tr>
 <tr><td>LIC(%):</td><td><input type="text" name="lic"></td></tr>

 <tr><td><input type="submit" value="Evaluate & Store"></td>
 <td><input type="reset" value="Reset"></td></tr>
 </table>
 
 </body>
</html>


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

<%
   
    String ename=request.getParameter("ename");
    String empid=request.getParameter("empid");
    String dept=request.getParameter("dept");
    String des=request.getParameter("des");
    double bsal=Double.valueOf(request.getParameter("bsal"));
    double ta=Double.valueOf(request.getParameter("ta"));
    double ta2=bsal*ta/100;
    double da=Double.valueOf(request.getParameter("da"));
    double da2=bsal*da/100;
    double hra=Double.valueOf(request.getParameter("hra"));
    double hra2=bsal*hra/100;
    double pf=Double.valueOf(request.getParameter("pf"));
    double pf2=bsal*pf/100;
    double lic=Double.valueOf(request.getParameter("lic"));
    double lic2=bsal*lic/100;
    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
    {
        out.println("<h2>Information Stored Successfully!</h2>");
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con=DriverManager.getConnection("jdbc:odbc:emp24");
        Statement st=con.createStatement();
        String s="insert into emp24 values('"+ename+"','"+empid+"','"+dept+"','"+des+"',"
            +bsal+","+ta2+","+da2+","+hra2+","+allowance+","+gsal+","+pf2+","+lic2+","
            +deduction+","+netsal+");";
        st.executeQuery(s);
    }
    catch(Exception e)
    {
        //out.println(e);
    }
%>
</body>
</html>
 


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>






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

Filename:Stud22.html
<!-- 22. Program to read student info. and store into database -->
<html>
 <head>

 <title>Student Information</title>
 </head>
 <body>
 <h3>Enter Student Details:<h3>
 <form action="Stud22.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:Stud22.jsp
<!-- 22. 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:stud22");
    Statement st=con.createStatement();
    try
    {
        out.println("<h3>Data Saved Successfully!</h3>");
        String s="insert into stud22 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>
 


16. HTML and JSP Program to Retrieve Employee Information from the Database.

Filename: Employee16.html
<!-- 16. HTML Program to accept Employee Name -->
<html>
 <head>

 <title>Employee Salary Statement</title>
 </head>
 <body>
 <h3>Enter the Name of Employee:<h3>
 <form action="Employee16.jsp" method="POST" >

    <input type="text" name="ename" autofocus><br><br>
    <input type="submit" value="Generate Statement">
  
 </body>
</html>

Filename: Employee16.jsp
<!-- 16. JSP Program to Retrieve Employee Information from the Database. -->
<html>
<head>
<title>Employee Salary Statement</title>
<%@page import="java.sql.*,java.util.*"%>
</head>
<body>
<%
    String ename=request.getParameter("ename");

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:emp16");
    Statement st=con.createStatement();
   
    ResultSet rs=st.executeQuery("select * from emp16 where ename='"+ename+"'");
   
    while(rs.next())
    {
%>
    <CENTER>
    <table border=5 bgcolor="orange" height=600 width=400 >
    <caption><h2><font color="blue" >SALARY STATEMENT</font></h2></caption>
    <tr><td>Name</td><td><%=rs.getString("ename")%></td></tr>
    <tr><td>Department</td><td><%=rs.getString("dept")%></td></tr>
    <tr><td>Designation</td><td><%=rs.getString("des")%></td></tr>
    <tr><td>Basic Salary</td><td><%=rs.getString("bsal")%></td></tr>
    <tr><td>TA</td><td><%=rs.getString("ta")%></td></tr>
    <tr><td>DA</td><td><%=rs.getString("da")%></td></tr>
    <tr><td>HRA</td><td><%=rs.getString("hra")%></td></tr>
    <tr><td>Gross Salary</td><td><%=rs.getString("gsal")%></td></tr>
    <tr><td>PF</td><td><%=rs.getString("pf")%></td></tr>

    <tr><td>IT</td><td><%=rs.getString("it")%></td></tr>
    <tr><td>Net Salary</td><td><%=rs.getString("netsal")%></td></tr>
    </table>
    </CENTER>

<%
    }
   

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

%>

</body>
</html>
FREE Hit Counters