10/29 6段階完了

This commit is contained in:
2026-10-29 10:28:59 +09:00
parent 395f2f4f90
commit c7f723ffe2
2 changed files with 93 additions and 0 deletions

View File

@@ -183,5 +183,49 @@ public class EmployeeDAO {
DbUtil.closeStatement(stmt);
}
}
//社員情報更新
public void empUpdate(
int id,
String name,
String kana,
String mail,
String password,
int departmentId)
throws SQLException {
//SQL作成
StringBuilder sql = new StringBuilder();
sql.append(" UPDATE employee ");
sql.append(" SET ");
sql.append(" nm_employee = ?, ");
sql.append(" kn_employee = ?, ");
sql.append(" mail_address = ?, ");
sql.append(" password = ?, ");
sql.append(" id_department = ? ");
sql.append(" WHERE id_employee = ? ");
try {
//PreparedStatement生成
stmt = con.prepareStatement(sql.toString());
//値設定
stmt.setString(1, name);
stmt.setString(2, kana);
stmt.setString(3, mail);
stmt.setString(4, password);
stmt.setInt(5, departmentId);
stmt.setInt(6, id);
// SQL実行
stmt.executeUpdate();
} finally {
// Statement切断
DbUtil.closeStatement(stmt);
}
}
}

View File

@@ -57,6 +57,7 @@ public class Main {
empInsert();
break;
case "3":
empUpdate();
break;
case "4":
empDelete();
@@ -245,5 +246,53 @@ public class Main {
DbUtil.closeConnection(empDao.con);
}
}
//社員情報更新
public static void empUpdate() throws ClassNotFoundException, SQLException {
//DB接続
Connection con = DbUtil.getConnection();
EmployeeDAO empDao = new EmployeeDAO(con);
try {
//更新対象ID入力
String strId = inputCheck("ID", true);
int id = Integer.parseInt(strId);
//存在チェック
List<EmployeeDTO> empList = empDao.selectById(id);
if (empList.size() == 0) {
System.out.println("入力された値で情報がみつかりませんでした");
return;
}
//社員名入力
String name = inputCheck("社員名", false);
//フリガナ入力
String kana = inputCheck("フリガナ", false);
//メールアドレス入力
String mail = inputCheck("メールアドレス", false);
//パスワード入力
String password = inputCheck("パスワード", false);
//部署ID入力
String departmentId = inputCheck("部署ID", true);
//更新処理
empDao.empUpdate(
id,
name,
kana,
mail,
password,
Integer.parseInt(departmentId));
System.out.println("更新が完了しました");
} finally {
DbUtil.closeConnection(empDao.con);
}
}
}