diff --git a/src/com/rhizome/example/dao/EmployeeDAO.java b/src/com/rhizome/example/dao/EmployeeDAO.java index ef63c49..9e001f5 100644 --- a/src/com/rhizome/example/dao/EmployeeDAO.java +++ b/src/com/rhizome/example/dao/EmployeeDAO.java @@ -13,6 +13,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import com.rhizome.example.dto.EmployeeDTO; import com.rhizome.example.util.DbUtil; public class EmployeeDAO { @@ -48,8 +49,8 @@ public class EmployeeDAO { * @throws SQLException * @throws ClassNotFoundException */ - public List selectAll() throws SQLException, ClassNotFoundException { - List rtnList = new ArrayList<>(); + public List selectAll() throws SQLException, ClassNotFoundException { + List rtnList = new ArrayList<>(); StringBuilder sql = new StringBuilder(); sql.append(" SELECT "); sql.append(" " + "*"); @@ -60,7 +61,10 @@ public class EmployeeDAO { this.stmt = con.prepareStatement(sql.toString()); rs = stmt.executeQuery(); while (rs.next()) { - rtnList.add(rs.getString(NM_EMPLOYEE)); + EmployeeDTO dto = new EmployeeDTO(rs.getInt(ID_EMPLOYEE), rs.getString(NM_EMPLOYEE), + rs.getString(KN_EMPLOYEE), rs.getString(MAIL_ADDRESS), rs.getString(PASSWORD), + rs.getInt(ID_DEPARTMENT)); + rtnList.add(dto); } } finally { DbUtil.closeStatement(this.stmt); diff --git a/src/com/rhizome/example/main/Main.java b/src/com/rhizome/example/main/Main.java index 14fb220..1babd54 100644 --- a/src/com/rhizome/example/main/Main.java +++ b/src/com/rhizome/example/main/Main.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Scanner; import com.rhizome.example.dao.EmployeeDAO; +import com.rhizome.example.dto.EmployeeDTO; import com.rhizome.example.util.DbUtil; /** @@ -76,7 +77,7 @@ public class Main { * @throws SQLException */ public static void empSelect() throws ClassNotFoundException, SQLException { - List empList = new ArrayList<>(); + List empList = new ArrayList<>(); Connection con = DbUtil.getConnection(); EmployeeDAO empDao = new EmployeeDAO(con); System.out.println("1:全検索 2:条件検索 それ以外:戻る"); @@ -89,8 +90,8 @@ public class Main { default: return; } - for (String emp : empList) { - System.out.println(emp); + for (EmployeeDTO emp : empList) { + emp.showInfo(); } } finally { DbUtil.closeConnection(empDao.con);