package com.cin.test.util;
import java.sql.*;
import com.cin.dto.EmploymentStatusDTO;
public class EmploymentTable extends Table {
public EmploymentTable(Connection connection) {
super("employmentstat", connection);
}
public void init() throws SQLException {
Statement stmt = connection.createStatement();
try{
stmt.execute("insert into employmentstat (SSN, UNEMPLOYMENTREASON, EMPLOYMENTSTAT) values (10, null, ' Full-time schedules')");
stmt.execute("insert into employmentstat (SSN, UNEMPLOYMENTREASON, EMPLOYMENTSTAT) values (11, null, ' Full-time schedules')");
stmt.execute("insert into employmentstat (SSN, UNEMPLOYMENTREASON, EMPLOYMENTSTAT) values (13, ' Other job loser', ' Children or Armed Forces')");
}finally{
stmt.close();
}
}
public EmploymentStatusDTO getRow(int ssn) throws SQLException {
PreparedStatement stmt = connection.prepareStatement(
"SELECT * " +
"FROM "+getName()+" " +
"WHERE ssn = ?");
try{
stmt.setInt(1, ssn);
stmt.execute();
ResultSet rs = stmt.getResultSet();
if( rs.next() ){
EmploymentStatusDTO dto = new EmploymentStatusDTO();
dto.setEmploymentStatus(rs.getString("employmentstat"));
dto.setUnemploymentReason(rs.getString("unemploymentreason"));
return dto;
} else {
return null;
}
}finally{
stmt.close();
}
}
}