Stept 6 (UPDATE)
This commit is contained in:
@@ -167,4 +167,33 @@ public class EmployeeDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public void empUpdate (String nmemp, String knname,String mail, String pw, int deptId,int empId) throws ClassNotFoundException, SQLException{
|
||||||
|
StringBuilder sql = new StringBuilder();
|
||||||
|
sql.append("UPDATE ");
|
||||||
|
sql.append(" " + TBL_NAME);
|
||||||
|
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 ");
|
||||||
|
sql.append(" " + ID_EMPLOYEE + " = ? ");
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.stmt = con.prepareStatement(sql.toString());
|
||||||
|
this.stmt.setString(1, nmemp);
|
||||||
|
this.stmt.setString(2, knname);
|
||||||
|
this.stmt.setString(3, mail);
|
||||||
|
this.stmt.setString(4, pw);
|
||||||
|
this.stmt.setInt(5, deptId);
|
||||||
|
this.stmt.setInt(6, empId);
|
||||||
|
|
||||||
|
this.stmt.executeUpdate();
|
||||||
|
} finally {
|
||||||
|
DbUtil.closeStatement(this.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();
|
||||||
@@ -72,6 +73,43 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void empUpdate() throws ClassNotFoundException, SQLException{
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
Connection con = DbUtil.getConnection();
|
||||||
|
EmployeeDAO empDao = new EmployeeDAO(con);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// ID ရိုက်ထည့်ခိုင်းခြင်း
|
||||||
|
String strId = inputCheck("ID", true);
|
||||||
|
int id = Integer.parseInt(strId);
|
||||||
|
|
||||||
|
// ID ရှိမရှိ စစ်ဆေးခြင်း (selectById ကို သုံးပါ)
|
||||||
|
List<EmployeeDTO> empList = empDao.selectById(id);
|
||||||
|
if (empList.isEmpty()) {
|
||||||
|
System.out.println("入力された値で情報がみつかりませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// အချက်အလက် အသစ်များ တောင်းခံခြင်း
|
||||||
|
String name = inputCheck("社員名", false);
|
||||||
|
String kana = inputCheck("フリガナ", false);
|
||||||
|
String mail = inputCheck("メールアドレス", false);
|
||||||
|
String pass = inputCheck("パスワード", false);
|
||||||
|
|
||||||
|
String strDeptId = inputCheck("部署ID", true);
|
||||||
|
int deptId = Integer.parseInt(strDeptId);
|
||||||
|
|
||||||
|
// DB ထဲသို့ ပြင်ဆင်ချက် ထည့်သွင်းခြင်း
|
||||||
|
empDao.empUpdate(name, kana, mail, pass, deptId,id);
|
||||||
|
System.out.println("更新が完了しました");
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
DbUtil.closeConnection(empDao.con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void empInsert() throws ClassNotFoundException, SQLException {
|
public static void empInsert() throws ClassNotFoundException, SQLException {
|
||||||
Connection con = DbUtil.getConnection();
|
Connection con = DbUtil.getConnection();
|
||||||
EmployeeDAO empDao = new EmployeeDAO(con);
|
EmployeeDAO empDao = new EmployeeDAO(con);
|
||||||
|
|||||||
Reference in New Issue
Block a user