4段階目終了

This commit is contained in:
2026-09-30 14:32:50 +09:00
parent c65c3b1db8
commit 0062b9fce4
3 changed files with 51 additions and 0 deletions

View File

@@ -101,4 +101,17 @@ public class EmployeeDAO {
} }
return list; return list;
} }
// 社員テーブルから指定された社員IDに一致するデータを削除する
public void empDelete(int id_employee) throws SQLException {
String sql = "DELETE FROM employee WHERE ID_EMPLOYEE = ?";
try {
this.stmt = con.prepareStatement(sql);
this.stmt.setInt(1, id_employee);
this.stmt.executeUpdate();
} finally {
DbUtil.closeStatement(this.stmt);
}
}
} }

View File

@@ -58,6 +58,7 @@ public class Main {
case "3": case "3":
break; break;
case "4": case "4":
empDelete();
break; break;
case "9": case "9":
return; return;
@@ -103,6 +104,43 @@ public class Main {
} }
} }
public static void empDelete() throws ClassNotFoundException, SQLException {
Connection con = DbUtil.getConnection();
EmployeeDAO empDao = new EmployeeDAO(con);
try {
System.out.println("IDを入力してください");
String input = sc.nextLine();
// 空文字が入力された場合
if (input.strip().isEmpty()) {
System.out.println("入力された値で情報がみつかりませんでした");
return;
}
int inputId = Integer.parseInt(input.strip());
List<EmployeeDTO> empList = empDao.selectById(inputId);
// 検索結果が存在しないIDの場合
if (empList.isEmpty()) {
System.out.println("入力された値で情報がみつかりませんでした");
return;
}
System.out.println("指定されたIDの情報を削除します? Y/y");
System.out.println("(Y/y以外の入力であればキャンセル)");
String confilm = sc.nextLine();
// 検索結果が存在した場合
if ("Y".equalsIgnoreCase(confilm)) {
empDao.empDelete(inputId);
System.out.println("社員ID" + input + "のデータを削除しました");
} else {
System.out.println("削除をキャンセルしました");
}
} catch (NumberFormatException e) {
System.out.println("入力された値で情報がみつかりませんでした");
} finally {
DbUtil.closeConnection(empDao.con);
}
}
/** /**
* フラグを判定し、テーブル名を取得する * フラグを判定し、テーブル名を取得する
* *