0% found this document useful (0 votes)
17 views17 pages

Ajp Munish 5,6

The document outlines the procedures for creating an Employee Payslip using JSP and a JDBC program for data manipulation in a database. It includes steps for designing a web application form, calculating employee pay components, and executing database operations such as creating, inserting, updating, and deleting records. The provided code snippets demonstrate the implementation of these functionalities.

Uploaded by

mei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views17 pages

Ajp Munish 5,6

The document outlines the procedures for creating an Employee Payslip using JSP and a JDBC program for data manipulation in a database. It includes steps for designing a web application form, calculating employee pay components, and executing database operations such as creating, inserting, updating, and deleting records. The provided code snippets demonstrate the implementation of these functionalities.

Uploaded by

mei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

EX.

NO: 5 EMPLOYEE PAYSLIP

AIM:

To Prepare a Employee pay slip using JSP.

PROCEDURE:

Step 1: Start the process

Step 2: Create a web application by choosing file-new project-web-web application.

Step 3: Design a form with fields like employee name, number , designation, basic pay, total

working day and present day.

Step 4: Create a separate JSP file by choosing file-new file.

Step 5: Create and link the jsp variable with the HTML variable.

Step 6: Using parseint function change the string value into integer value

Step 7: Calculate HRA,DA,TA,NPAY, GROSS PAY using the provided details.

Step 8: Run the program

Step 9: Stop the process

1
PROGRAM:

Index.jsp

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>

<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> --%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Employee Payslip</title>
</head>
<body bgcolor="orange">
<h1><center>GANAPATHY TEXTTILES [P] LTD.</center></h1>
<h2><center>2,Ramanujam Nagar,Coimbatore</center></h2>
<h2><center>Employee Payslip</center></h2>
<form action="pgm.jsp" method="get">

<table>
<tr>
<td>Employee Name: <input type="text" name="ename"></td>
<td>Employee N# <input type="text" name="eno"></td> </tr>

2
<tr> <td>Desigination
<select name="jobtype">
<option value="manager">Manager</option>
<option value="accountant">Accountant</option>
<option value="Labout">Labour</option>
</select>
</td></tr>

<tr><td>Basic Pay(per day)<input type="text" name="pay"></td>


<td>Total Working Days<input type="text" name="work"></td>
<td>No. Day Present<input type="text" name="present"></td>
</tr>
<tr><td><input type="submit" name="submit" value="calculate"></td>
</tr> </table>
</form>
</body>
</html>

Pgm.jsp

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>

<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> --%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

3
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Employee Payslip</title>
</head>
<body>
<h1>Employee Payslip</h1>
<%
int total,hra,da,ta,npay,gpay;
String en = request.getParameter("ename");
String et = request.getParameter("eno");
String jt = request.getParameter("jt");
String p = request.getParameter("pay");
String w = request.getParameter("work");
String pr = request.getParameter("present");
%>
EMPLOYEE NAME : <%=en%>
EMPLOYEE CODE : <%=et%>
<table name=t width=60% height=60% border=1>
<tr><td>Present Days</td>
<td>:</td>
<td> <%=pr%></td>
</tr>
<tr><td>BasicPay</td>
<td>:</td>
<td><%=p%></td>
</tr>
<%total=Integer.parseInt(p)*Integer.parseInt(pr); %>
<tr><td>Monthly Pay</td>
<td>:</td>
<td> <%=total%></td>
</tr>

4
<%hra=(total)*5/100; %>
<tr><td>HRA</td>
<td>:</td>
<td> <%=hra%></td>
</tr>

<%da=(total)*7/100; %>
<tr><td>DA </td>
<td>:</td>
<td> <%=da%></td>
</tr>

<%ta=(total)*5/100; %>
<tr><td>TA </td>
<td>:</td>
<td> <%=ta%></td>
</tr>

<%gpay=total+hra+da; %>
<tr><td>Gross Pay </td>
<td>:</td>
<td> <%=gpay%></td>
</tr>

<%npay=gpay-ta; %>
<tr><td>NET PAY </td>
<td>:</td>
<td> <%=npay%></td>
</tr>
</table>
</body>
</html>

5
OUTPUT:

6
RESULT:
The above program has been successfully implemented.

7
EX. NO: 6. DATA MANIPULATION

AIM:
To Write a program using JDBC for creating a table, Inserting, Deleting
records and list out the records.

PROCEDURE:

Step 1: Start the process

Step 2: Create a table I oracle with desired fields.

Step 3: Connect the java and database using JDBC using getconnection

attribute.

Step 4: Create a table using create table statement with statement.execute

function

Step 5: Insert different values to the database using insert statement

Step 6: Using update statement update the old value to new value.

Step 7: Delete the row in the database using delete statement

Step 8: Display the result

Step 9: Stop the process.

8
PROGRAM

To make a table in Oracle

CREATE TABLE emp(id int primary key,name varchar(15),department int,salary


int,location varchar(20))

emp.java

import java.io.*;
public class emp {
private static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
private static final String DATABASE_URL = "jdbc:mysql://localhost/hr";
private static final String USERNAME = "admin";
private static final String PASSWORD = "secret";
public static void createTable(){
Connection connection = null;
Statement statement = null;
try
{
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL, USERNAME,
PASSWORD);
statement = connection.createStatement();
//boolean b=statement.execute("DROP TABLE IF EXISTS emp");
boolean b=statement.execute("CREATE TABLE emp(id int primary key,name
varchar(15),department int,salary int,location varchar(20))");
if(b==true)
System.out.println("Tables created...");
}
catch (SQLException sqlEx)
{
sqlEx.printStackTrace();
System.exit(1);

9
}
catch (ClassNotFoundException clsNotFoundEx)
{
clsNotFoundEx.printStackTrace();
System.exit(1);
}
finally
{
try
{
statement.close();
connection.close();
}
catch (Exception e)
{
System.exit(1);
}
}
}

public static void createEmployee(int id, String name, int dept, int sal, String loc)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,
USERNAME,PASSWORD);
preparedStatement = connection.prepareStatement("INSERT INTO emp
VALUES(?,?,?,?,?)");
preparedStatement.setInt(1, id);
preparedStatement.setString(2, name);
preparedStatement.setInt(3, dept);

10
preparedStatement.setInt(4, sal);
preparedStatement.setString(5, loc);
boolean b=preparedStatement.execute();
if(b==true)
System.out.println("1 record inserted...");
}
catch (SQLException sqlEx)
{
sqlEx.printStackTrace(); System.exit(1);
}
catch (ClassNotFoundException clsNotFoundEx)
{
clsNotFoundEx.printStackTrace(); System.exit(1);
}
finally
{
try
{
preparedStatement.close();
connection.close();
}
catch (Exception e)
{
System.exit(1);
}
}
}
public static void updateSalary(int id, int raise)
{
Connection connection = null; PreparedStatement preparedStatement = null;
try
{
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,

11
USERNAME,PASSWORD);
preparedStatement = connection.prepareStatement("UPDATE emp SET
salary=salary+? WHERE id=?");
preparedStatement.setInt(1, raise);
preparedStatement.setInt(2, id);
boolean b=preparedStatement.execute();
System.out.println("Employee updated…”);
if(b==true)
System.out.println("$"+raise+" raised for emp id="+id);
}
catch (SQLException sqlEx)
{
sqlEx.printStackTrace();
System.exit(1);
}
catch (ClassNotFoundException clsNotFoundEx)
{
clsNotFoundEx.printStackTrace();
System.exit(1);
}
finally
{
try
{
preparedStatement.close();
connection.close();
}
catch (Exception e)
{
System.exit(1);
} } }
public static void deleteEmployee(int id)
{
Connection connection = null; PreparedStatement preparedStatement = null;

12
try
{
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,
USERNAME,PASSWORD);
preparedStatement = connection.prepareStatement("DELETE FROM emp WHERE
id=?");
preparedStatement.setInt(1, id);
boolean b=preparedStatement.execute();
if(b==true)
System.out.println("1 record deleted...");
}
catch (SQLException sqlEx)
{
sqlEx.printStackTrace(); System.exit(1);
}
catch (ClassNotFoundException clsNotFoundEx)
{
clsNotFoundEx.printStackTrace();
System.exit(1);
}
finally
{
try
{
preparedStatement.close();
connection.close();
}
catch (Exception e)
{
System.exit(1);
}} }

13
public static void readEmployee(int id)
{
Connection connection = null;
Statement statement = null;
try
{
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL, USERNAME,
PASSWORD);
statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM emp WHERE
id="+id);
ResultSetMetaData metaData = resultSet.getMetaData(); int noCols =
metaData.getColumnCount(); for (int i = 1; i <= noCols; i++)
{
if (i != 3)
System.out.printf("%-10s\t", metaData.getColumnName(i).toUpperCase());
}
System.out.println();
while (resultSet.next()) {
for (int i = 1; i <= noCols; i++)
{
if (i != 3)
System.out.printf("%-10s\t", resultSet.getObject(i));
}
System.out.println();
}
}
catch (SQLException sqlEx)
{
sqlEx.printStackTrace();
System.exit(1);
}
catch (ClassNotFoundException clsNotFoundEx)

14
{
clsNotFoundEx.printStackTrace();
System.exit(1);
}
finally
{
try
{
statement.close();
connection.close();
}
catch (Exception e)
{
System.exit(1);
}}}
public static void main(String[] args)
{
//createTable();
createEmployee(1234, "Larson", 123, 1200, "New Jersey"); createEmployee(5678,
"Jones", 123, 1100, "New Jersey"); createEmployee(7890, "Kapil", 345, 1600, "Los
Angeles"); createEmployee(2341, "Myers", 123, 1800, "New Jersey");
createEmployee(6784, "Bruce", 345, 2200, "Los Angeles"); createEmployee(9636,
"Neumann", 123, 3200, "New Jersey"); updateSalary(1234, 1000);
createEmployee(1111, "Lee", 123, 4400, "New Jersey");
deleteEmployee(1111);
readEmployee(6784);
}
}

15
OUTPUT:

16
RESULT:

Thus the above program has been executed successfully.

17

You might also like