From d2ebdbd11cc5287c0c924bc51e1af865e8be056a Mon Sep 17 00:00:00 2001 From: m-shimizu <26-m-e-stella-tecnica@it-college.jp> Date: Wed, 30 Sep 2026 12:36:02 +0900 Subject: [PATCH] =?UTF-8?q?2=E6=AE=B5=E9=9A=8E=E7=9B=AE=EF=BC=88=E5=90=8D?= =?UTF-8?q?=E5=89=8D=E6=A4=9C=E7=B4=A2=E3=81=8B=E3=82=89=E5=85=A8=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=BF=E6=A4=9C=E7=B4=A2=E3=81=AB=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/rhizome/example/dao/EmployeeDAO.java | 15 ++++- src/com/rhizome/example/dto/EmployeeDTO.java | 59 ++++++++++++++++++++ src/com/rhizome/example/main/Main.java | 13 ++++- 3 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 src/com/rhizome/example/dto/EmployeeDTO.java diff --git a/src/com/rhizome/example/dao/EmployeeDAO.java b/src/com/rhizome/example/dao/EmployeeDAO.java index ef63c49..b9a0cfc 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,15 @@ 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(); + dto.setIdEmployee(rs.getInt(ID_EMPLOYEE)); + dto.setNmEmployee(rs.getString(NM_EMPLOYEE)); + dto.setKnEmployee(rs.getString(KN_EMPLOYEE)); + dto.setMailAddress(rs.getString(MAIL_ADDRESS)); + dto.setPassword(rs.getString(PASSWORD)); + dto.setIdDepartment(rs.getInt(ID_DEPARTMENT)); + + rtnList.add(dto); } } finally { DbUtil.closeStatement(this.stmt); diff --git a/src/com/rhizome/example/dto/EmployeeDTO.java b/src/com/rhizome/example/dto/EmployeeDTO.java new file mode 100644 index 0000000..39e92b0 --- /dev/null +++ b/src/com/rhizome/example/dto/EmployeeDTO.java @@ -0,0 +1,59 @@ +package com.rhizome.example.dto; + +public class EmployeeDTO { + private int idEmployee; + private String nmEmployee; + private String knEmployee; + private String mailAddress; + private String password; + private int idDepartment; + + public int getIdEmployee() { + return idEmployee; + } + + public void setIdEmployee(int idEmployee) { + this.idEmployee = idEmployee; + } + + public String getNmEmployee() { + return nmEmployee; + } + + public void setNmEmployee(String nmEmployee) { + this.nmEmployee = nmEmployee; + } + + public String getKnEmployee() { + return knEmployee; + } + + public void setKnEmployee(String knEmployee) { + this.knEmployee = knEmployee; + } + + public String getMailAddress() { + return mailAddress; + } + + public void setMailAddress(String mailAddress) { + this.mailAddress = mailAddress; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public int getIdDepartment() { + return idDepartment; + } + + public void setIdDepartment(int idDepartment) { + this.idDepartment = idDepartment; + } + +} diff --git a/src/com/rhizome/example/main/Main.java b/src/com/rhizome/example/main/Main.java index 14fb220..0e080e6 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,14 @@ public class Main { default: return; } - for (String emp : empList) { - System.out.println(emp); + for (EmployeeDTO emp : empList) { + System.out.println( + emp.getIdEmployee() + " " + + emp.getNmEmployee() + " " + + emp.getKnEmployee() + " " + + emp.getMailAddress() + " " + + emp.getPassword() + " " + + emp.getIdDepartment()); } } finally { DbUtil.closeConnection(empDao.con);