package com.cin.test.util;
import java.sql.*;
import com.cin.dto.EducationDTO;
public class EducationTable extends Table {
public EducationTable(Connection connection) {
super("education", connection);
}
public void init() throws SQLException {
Statement stmt = connection.createStatement();
try{
stmt.execute("insert into education (SSN, EDUCATION, EDUENROLL) values (10, ' 1st 2nd 3rd or 4th grade', null)");
stmt.execute("insert into education (SSN, EDUCATION, EDUENROLL) values (11, ' Masters degree(MA MS MEng MEd MSW MBA)', null)");
stmt.execute("insert into education (SSN, EDUCATION, EDUENROLL) values (12, ' Children', null)");
// user 13 has no education
}finally{
stmt.close();
}
}
public EducationDTO getValue(int ssn) throws SQLException {
PreparedStatement stmt = connection.prepareStatement(
"SELECT education, eduenroll " +
"FROM education " +
"WHERE ssn = ? ");
try{
stmt.setInt(1, ssn);
stmt.execute();
ResultSet rs = stmt.getResultSet();
if( rs.next() ){
EducationDTO edu = new EducationDTO();
edu.setEducation(rs.getString(1));
edu.setEduenroll(rs.getString(2));
if( rs.next() ){
assert false;
throw new RuntimeException("Got more results than expected.");
}
return edu;
}
return null;
}finally{
stmt.close();
}
}
}