Professional Documents
Culture Documents
Day 29 Assignment
Day 29 Assignment
Day 29 Assignment
Department
package com.canddella.entity;
Employee
package com.canddella.entity;
Com.canddella.dao
Department dao
package com.canddella.dao;
import java.util.List;
import com.canddella.entity.Department;
import com.canddella.entity.Employee;
public interface DepartmentDAO {
Departmentdao impl
package com.canddella.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import com.canddella.dbconnectionpool.DBConnectionPool;
import com.canddella.entity.Department;
@Override
public List<Department> getDepartment() {
try {
DataSource ds = DBConnectionPool.getDataSource();
connection = ds.getConnection();
prepStmt = connection.prepareStatement(selectSQL);
ResultSet resultSet = prepStmt.executeQuery();
while(resultSet.next())
{
String departmentId =
resultSet.getString(1);
String departmentType =
resultSet.getString(2);
String DepartmentName =
resultSet.getString(3);
String location = resultSet.getString(4);
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return departmentList;
@Override
public int insertDepartmentDetails(Department department) {
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
DataSource ds = DBConnectionPool.getDataSource();
connection = ds.getConnection();
preparedStatement =
connection.prepareStatement(INSERT_SQL);
preparedStatement.setString(1,department.getDepartment_id());
preparedStatement.setString(2,department.getDepartment_name());
preparedStatement.setString(3,department.getDepartment_type());
preparedStatement.setString(4,department.getLocation());
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
@Override
public List<Department> particularDepartment() {
try {
DataSource ds = DBConnectionPool.getDataSource();
connection = ds.getConnection();
prepStmt = connection.prepareStatement(selectSQL);
ResultSet resultSet = prepStmt.executeQuery();
while(resultSet.next())
{
String departmentId =
resultSet.getString(1);
String departmentType =
resultSet.getString(2);
String DepartmentName =
resultSet.getString(3);
String location = resultSet.getString(4);
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return departmentList;
}
employeeDao
package com.canddella.dao;
import java.util.List;
import com.canddella.entity.Department;
import com.canddella.entity.Employee;
employeeDao iml
package com.canddella.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import com.canddella.dbconnectionpool.DBConnectionPool;
import com.canddella.entity.Department;
import com.canddella.entity.Employee;
@Override
public List<Employee> getEmployees() {
try {
DataSource ds = DBConnectionPool.getDataSource();
connection = ds.getConnection();
prepStmt = connection.prepareStatement(selectSQL);
ResultSet resultSet = prepStmt.executeQuery();
while(resultSet.next())
{
String employeeId =
resultSet.getString(1);
String employeeFName =
resultSet.getString(2);
String employeeLName =
resultSet.getString(3);
String department =
resultSet.getString(4);
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return employeeList;
@Override
public int insertEmployee(Employee employee) {
preparedStatement.setString(1,employee.getEmployeeId());
preparedStatement.setString(2,employee.getEmployeeFName());
preparedStatement.setString(3,employee.getEmployeeLName());
preparedStatement.setString(4,employee.getDepartment());
preparedStatement.setInt(5,employee.getSalary());
int row = preparedStatement.executeUpdate();
return row;
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
@Override
public List<Employee> particularEmployee() {
try {
DataSource ds = DBConnectionPool.getDataSource();
connection = ds.getConnection();
prepStmt = connection.prepareStatement(selectSQL);
ResultSet resultSet = prepStmt.executeQuery();
while(resultSet.next())
{
String employeeId =
resultSet.getString(1);
String employeeFName =
resultSet.getString(2);
String employeeLName =
resultSet.getString(3);
String department =
resultSet.getString(4);
int salary = resultSet.getInt(5);
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return employeeList;
Com.canddella.dbconnectionpool
Connectionpool
package com.canddella.dbconnectionpool;
import java.beans.PropertyVetoException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import com.mchange.v2.c3p0.ComboPooledDataSource;
static {
try {
properties.load(inputStream);
dataSource.setJdbcUrl(properties.getProperty("CONNECTION_STRING"));
dataSource.setUser(properties.getProperty("USER"));
dataSource.setPassword(properties.getProperty("PASSWORD"));
dataSource.setInitialPoolSize(5);
dataSource.setMinPoolSize(5);
dataSource.setAcquireIncrement(5);
dataSource.setMaxPoolSize(20);
}catch(IOException | PropertyVetoException e) {
e.printStackTrace();
return dataSource;
Com.canddella.service
departmentService
package com.canddella.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import com.canddella.dao.DepartmentDAOImpl;
import com.canddella.entity.Department;
import com.canddella.entity.Employee;
departmentList = departmentDAOImpl.getDepartment();
return departmentList;
String departmentId=scanner.nextLine();
String departmentName=scanner.nextLine();
String departmentType=scanner.nextLine();
System.out.println("enter the location");
String location=scanner.nextLine();
if (row == 1)
System.out.println("INSERTED SUCCESSFULLY!!!!!!!!!!!!");
else
System.out.println("INSERTION FAILED!!!!!!!!!!!!");
System.out.println("**********main menu*********");
System.out.println("4.exit");
return departmentList;
Employee Service
package com.canddella.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import com.canddella.dao.EmployeeDAOImpl;
import com.canddella.entity.Department;
import com.canddella.entity.Employee;
return employeeList;
String employeeId=scanner.nextLine();
String employeeFName=scanner.nextLine();
String employeeLName=scanner.nextLine();
String department=scanner.nextLine();
int salary=scanner.nextInt();
if (row == 1)
System.out.println("INSERTED SUCCESSFULLY!!!!!!!!!!!!");
else
System.out.println("INSERTION FAILED!!!!!!!!!!!!");
}
public static void mainMenu()
System.out.println("**********main menu*********");
System.out.println("4.exit");
employeeList = employeeDAOImpl.particularEmployee();
return employeeList;
Com.canddella.utility
employeedepartmentUtility
package com.canddella.utility;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import com.canddella.dao.DepartmentDAOImpl;
import com.canddella.entity.Department;
import com.canddella.entity.Employee;
import com.canddella.service.DepartmentService;
import com.canddella.service.EmployeeService;
System.out.println("************main menu***********");
System.out.println("1. employee");
System.out.println("2. department");
System.out.println("3.exit");
if(choice1==1)
{
EmployeeService.mainMenu();
if(choice==1)
EmployeeService.insertEmployee();
if(choice==2)
employeeList = EmployeeService.getEmployees();
System.out.println("***************Employee
Details****************");
System.out.println(employee.getEmployeeId()+"
"+employee.getEmployeeFName()+" "+employee.getEmployeeLName()+"
"+employee.getDepartment()+" "+employee.getSalary());
if(choice==3)
{
List<Employee> employeeList = new ArrayList();
employeeList = EmployeeService.particularEmployee();
System.out.println("***************Employee
Details****************");
System.out.println(employee.getEmployeeId()+"
"+employee.getEmployeeFName()+" "+employee.getEmployeeLName()+"
"+employee.getDepartment()+" "+employee.getSalary());
if(choice==4)
System.out.println("Exit");
if(choice1==2)
EmployeeService.mainMenu();
if(choice3==1)
{
DepartmentService.insertDepartmentDetails();
if(choice3==2)
departmentList = DepartmentService.getDepartment();
System.out.println("***************Department
Details****************");
System.out.println(department.getDepartment_id()+"
"+department.getDepartment_type()+" "+department.getDepartment_name()+"
"+department.getLocation());
if(choice3==3)
departmentList = DepartmentService.getparticularDepartment();
System.out.println("***************Department
Details****************");
{
System.out.println(department.getDepartment_id()+"
"+department.getDepartment_name()+" "+department.getDepartment_type()+"
"+department.getLocation());
if(choice3==4)
System.out.println("Exit");