10/29 6段階完了
This commit is contained in:
@@ -184,4 +184,48 @@ public class EmployeeDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//社員情報更新
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public class Main {
|
|||||||
empInsert();
|
empInsert();
|
||||||
break;
|
break;
|
||||||
case "3":
|
case "3":
|
||||||
|
empUpdate();
|
||||||
break;
|
break;
|
||||||
case "4":
|
case "4":
|
||||||
empDelete();
|
empDelete();
|
||||||
@@ -246,4 +247,52 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//社員情報更新
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user