2段階目終了

This commit is contained in:
2026-09-29 16:53:16 +09:00
parent 4f60de10c4
commit e5fef82677
2 changed files with 14 additions and 5 deletions

View File

@@ -13,6 +13,7 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.rhizome.example.dto.EmployeeDTO;
import com.rhizome.example.util.DbUtil; import com.rhizome.example.util.DbUtil;
public class EmployeeDAO { public class EmployeeDAO {
@@ -48,8 +49,8 @@ public class EmployeeDAO {
* @throws SQLException * @throws SQLException
* @throws ClassNotFoundException * @throws ClassNotFoundException
*/ */
public List<String> selectAll() throws SQLException, ClassNotFoundException { public List<EmployeeDTO> selectAll() throws SQLException, ClassNotFoundException {
List<String> rtnList = new ArrayList<>(); List<EmployeeDTO> rtnList = new ArrayList<>();
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.append(" SELECT "); sql.append(" SELECT ");
sql.append(" " + "*"); sql.append(" " + "*");
@@ -60,7 +61,14 @@ public class EmployeeDAO {
this.stmt = con.prepareStatement(sql.toString()); this.stmt = con.prepareStatement(sql.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
rtnList.add(rs.getString(NM_EMPLOYEE)); EmployeeDTO dto = new EmployeeDTO();
dto.setID_EMPLOYEE(rs.getInt("ID_EMPLOYEE"));
dto.setNM_EMPLOYEE(rs.getString("NM_EMPLOYEE"));
dto.setKN_EMPLOYEE(rs.getString("KN_EMPLOYEE"));
dto.setMAIL_ADDRESS(rs.getString("MAIL_ADDRESS"));
dto.setPASSWORD(rs.getString("PASSWORD"));
dto.setID_DEPARTMENT(rs.getInt("ID_DEPARTMENT"));
rtnList.add(dto);
} }
} finally { } finally {
DbUtil.closeStatement(this.stmt); DbUtil.closeStatement(this.stmt);

View File

@@ -7,6 +7,7 @@ import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import com.rhizome.example.dao.EmployeeDAO; import com.rhizome.example.dao.EmployeeDAO;
import com.rhizome.example.dto.EmployeeDTO;
import com.rhizome.example.util.DbUtil; import com.rhizome.example.util.DbUtil;
/** /**
@@ -76,7 +77,7 @@ public class Main {
* @throws SQLException * @throws SQLException
*/ */
public static void empSelect() throws ClassNotFoundException, SQLException { public static void empSelect() throws ClassNotFoundException, SQLException {
List<String> empList = new ArrayList<>(); List<EmployeeDTO> empList = new ArrayList<>();
Connection con = DbUtil.getConnection(); Connection con = DbUtil.getConnection();
EmployeeDAO empDao = new EmployeeDAO(con); EmployeeDAO empDao = new EmployeeDAO(con);
System.out.println("1:全検索 2:条件検索 それ以外:戻る"); System.out.println("1:全検索 2:条件検索 それ以外:戻る");
@@ -89,7 +90,7 @@ public class Main {
default: default:
return; return;
} }
for (String emp : empList) { for (EmployeeDTO emp : empList) {
System.out.println(emp); System.out.println(emp);
} }
} finally { } finally {