1030自主学習
This commit is contained in:
@@ -37,3 +37,4 @@ INSERT INTO department (nm_department) VALUES ('経理部');
|
||||
INSERT INTO department (nm_department) VALUES ('システム開発事業部');
|
||||
INSERT INTO department (nm_department) VALUES ('教育事業部');
|
||||
INSERT INTO department (nm_department) VALUES ('営業企画部');
|
||||
|
||||
|
||||
@@ -111,8 +111,6 @@ public class EmployeeDAO {
|
||||
|
||||
//指定された社員のデータを削除する
|
||||
public void empDelete(int id_employee)throws SQLException, ClassNotFoundException{
|
||||
//リスト作成
|
||||
List<EmployeeDTO> rtnList = new ArrayList<>();
|
||||
//SQL文の作成
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append(" DELETE ");
|
||||
@@ -136,7 +134,6 @@ public class EmployeeDAO {
|
||||
|
||||
public void empInsert(String name, String kana, String email,
|
||||
String password, Integer idDep)throws SQLException, ClassNotFoundException{
|
||||
List<EmployeeDTO> rtnList = new ArrayList<>();
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append(" INSERT ");
|
||||
sql.append(" " + " INTO ");
|
||||
@@ -162,4 +159,32 @@ public class EmployeeDAO {
|
||||
}
|
||||
}
|
||||
|
||||
public void empUpdate(Integer id, String name, String kana, String email,
|
||||
String password, Integer idDep)throws SQLException, ClassNotFoundException{
|
||||
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,name );
|
||||
this.stmt.setString(2,kana );
|
||||
this.stmt.setString(3,email );
|
||||
this.stmt.setString(4,password );
|
||||
this.stmt.setInt(5,idDep );
|
||||
this.stmt.setInt(6, id);
|
||||
stmt.executeUpdate();
|
||||
}finally {
|
||||
DbUtil.closeStatement(this.stmt);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ public class Main {
|
||||
empInsert();
|
||||
break;
|
||||
case "3":
|
||||
empUpdate();
|
||||
break;
|
||||
case "4":
|
||||
empDelete();
|
||||
@@ -210,4 +211,30 @@ public class Main {
|
||||
DbUtil.closeConnection(empDao.con);
|
||||
}
|
||||
}
|
||||
public static void empUpdate() throws ClassNotFoundException, SQLException{
|
||||
List<EmployeeDTO> empList = new ArrayList<>();
|
||||
Connection con = DbUtil.getConnection();
|
||||
EmployeeDAO empDao = new EmployeeDAO(con);
|
||||
try {
|
||||
String delId =inputCheck("ID", true);
|
||||
int ID = Integer.parseInt(delId);
|
||||
empList = empDao.selectById(ID);
|
||||
if(empList.isEmpty()) {
|
||||
System.out.println("入力された値で情報がみつかりませんでした");
|
||||
return;
|
||||
}
|
||||
|
||||
String name = inputCheck("社員名",false);
|
||||
String kana = inputCheck("フリガナ", false);
|
||||
String email = inputCheck("メールアドレス", false);
|
||||
String password = inputCheck("パスワード", false);
|
||||
String depId = inputCheck("部署ID", true);
|
||||
int dID = Integer.parseInt(depId);
|
||||
|
||||
empDao.empUpdate(ID,name,kana,email,password,dID);
|
||||
System.out.println("更新が完了しました");
|
||||
}finally {
|
||||
DbUtil.closeConnection(empDao.con);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user