beautypg.com

Modifying the employeedao.java class file, Modifying the employee.java file, Modifying the – HP Integrity NonStop H-Series User Manual

Page 134: Employeedao.java class, File, Employee.java

background image

employee.setEmail(rs.getString(5));
return employee;
}

}

Modifying the

EmployeeDao.java Class

File

To modify the

EmployeeDao.java

in

com.hp.empinfo.service

package, complete the

following steps:

1.

Add two new methods

getDetail

and

deleteEmployee

in the

EmployeeDao.java

class file to add the retrieve and delete functionality in the application.

2.

Add two

import

statements that are being used in the modified

EmployeeDao.java

file:

import com.hp.empinfo.domain.Employee;
import com.hp.empinfo.domain.EmployeeRowMapper;

After modification, your

EmployeeDao.java

file appears as:

package com.hp.empinfo.service;

import java.sql.SQLException;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import com.hp.empinfo.domain.Employee;
import com.hp.empinfo.domain.EmployeeRowMapper;

public class EmployeeDao extends JdbcDaoSupport {

public Employee getDetail(int empid) throws SQLException {

Employee employee;
employee = (Employee) getJdbcTemplate().queryForObject(
"select * from employee where emp_id =?",
new Object[] { empid }, new EmployeeRowMapper());
return employee;
}
public void insertDetail(int empid, String firstname, String lastname,
int age, String email) throws SQLException {
getJdbcTemplate().update("insert into employee values(?,?,?,?,?)",
new Object[] { empid, firstname, lastname, age, email });
}

public String deleteEmployee(int empid) {

getJdbcTemplate().update("delete from employee where emp_id= ?",
new Object[] { empid });
return "Employee deleted";
}
}

Modifying the

Employee.java

File

You must modify the

Employee.java

file in the

com.hp.empinfo.domain

package to add

a property

rord

, which can be used to distinguish between the retrieve and delete request.

Modify the POJO to add a new property

rord

and its getter and setters.

After modification, the

Employee.java

file appears as:

package com.hp.empinfo.domain;

public class Employee implements java.io.Serializable {

private int empid;;
private String firstname;
private String lastname;
private int age;
private String email;

134

Getting Started with Spring

This manual is related to the following products: