Package com.cin.test.util

Source Code of com.cin.test.util.JobTable

package com.cin.test.util;

import java.sql.*;

import com.cin.dto.JobDTO;

public class JobTable extends Table {
  public JobTable(Connection connection) {
    super("job", connection);
  }

  public void init() throws SQLException {
    Statement stmt = connection.createStatement();
    stmt.execute("INSERT INTO job (ssn, workclass, industrycode, occupationcode, unionmember, employersize, weekwage, selfemployed, workweeks) VALUES (10, 'private', 9, 1, 'Yes', 10, 800, 1, 40)");
    stmt.execute("INSERT INTO job (ssn, workclass, industrycode, occupationcode, unionmember, employersize, weekwage, selfemployed, workweeks) VALUES (11, 'private', 9, 1, 'No', 1, 900, 0, 20)");
    stmt.execute("INSERT INTO job (ssn, workclass, industrycode, occupationcode, unionmember, employersize, weekwage, selfemployed, workweeks) VALUES (12, 'private', 9, 1, null, 5, 1000, 0, 60)");
    stmt.execute("INSERT INTO job (ssn, workclass, industrycode, occupationcode, unionmember, employersize, weekwage, selfemployed, workweeks) VALUES (13, 'private', 9, 2, 'Yes', 5, 800, 1, 60)");
    stmt.execute("INSERT INTO job (ssn, workclass, industrycode, occupationcode, unionmember, employersize, weekwage, selfemployed, workweeks) VALUES (14, 'private', 8, 1, 'Yes', 5, 900, 1, 60)");
    stmt.close();
  }
 
  public JobDTO 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() ){
        JobDTO dto = new JobDTO();
        dto.setEmployerSize(rs.getInt("employersize"));
        dto.setIndustryCode(rs.getInt("industrycode"));
        dto.setOccupationCode(rs.getInt("occupationcode"));
        dto.setSelfEmployed(rs.getInt("selfemployed"));
        dto.setUnionMember(rs.getString("unionmember"));
        dto.setWeekWage(rs.getInt("weekwage"));
        dto.setWorkClass(rs.getString("workclass"));
        dto.setWorkWeeks(rs.getInt("workweeks"));
        return dto;
      } else {
        return null;
      }
    }finally{
      stmt.close();
    }
  }
}
TOP

Related Classes of com.cin.test.util.JobTable

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.