4段階目終了
This commit is contained in:
Binary file not shown.
@@ -101,4 +101,17 @@ public class EmployeeDAO {
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ public class Main {
|
||||
case "3":
|
||||
break;
|
||||
case "4":
|
||||
empDelete();
|
||||
break;
|
||||
case "9":
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* フラグを判定し、テーブル名を取得する
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user