必須段階実装完了

This commit is contained in:
2026-10-30 16:48:29 +09:00
parent f909550b87
commit 6493baccef
2 changed files with 69 additions and 61 deletions

View File

@@ -78,7 +78,8 @@ public class EmployeeDAO {
return rtnList;
}
public java.util.List<EmployeeDTO> selectById​(int id) throws java.sql.SQLException, java.lang.ClassNotFoundException, java.lang.NumberFormatException {
public java.util.List<EmployeeDTO> selectById​(int id)
throws java.sql.SQLException, java.lang.ClassNotFoundException, java.lang.NumberFormatException {
List<EmployeeDTO> rtnList = new ArrayList<>();
StringBuilder sql = new StringBuilder();
sql.append(" SELECT * FROM ");
@@ -128,52 +129,57 @@ public class EmployeeDAO {
DbUtil.closeStatement​(this.stmt);
}
}
public void empInsert​(java.lang.String name, java.lang.String kana, java.lang.String mail, java.lang.String pass, int depId) throws java.lang.NumberFormatException, java.sql.SQLException, java.lang.ClassNotFoundException{
public void empInsert​(java.lang.String name, java.lang.String kana, java.lang.String mail, java.lang.String pass,
int depId) throws java.lang.NumberFormatException, java.sql.SQLException, java.lang.ClassNotFoundException {
//List<EmployeeDTO> rtnList = new ArrayList<>();
StringBuilder sql = new StringBuilder();
sql.append(" INSERT INTO " + TBL_NAME);
sql.append(" (nm_employee, kn_employee, mail_address, password, id_department) ");
sql.append(" VALUES ");
sql.append(" (?, ?, ?, ?, ?) ");
try {
this.stmt = con.prepareStatement(sql.toString());
this.stmt.setString(1, name);
this.stmt.setString(2, kana);
this.stmt.setString(3, mail);
this.stmt.setString(4, pass);
this.stmt.setInt(5, depId);
this.stmt.executeUpdate();
} finally {
DbUtil.closeStatement​(this.stmt);
}
}
public void empUpdate​(int id, java.lang.String name, java.lang.String kana, java.lang.String mail, java.lang.String pass, int depId) throws java.lang.ClassNotFoundException, java.sql.SQLException, java.lang.NumberFormatException{
StringBuilder sql = new StringBuilder();
sql.append(" UPDATE " + TBL_NAME + " SET ");
sql.append(" (id_employee=?,nm_employee=?, kn_employee=?, mail_address=?, password=?, id_department=?) ");
sql.append(" WHERE id_employee = ? ");
sql.append(" (nm_employee, kn_employee, mail_address, password, id_department) ");
sql.append(" VALUES ");
sql.append(" (?, ?, ?, ?, ?) ");
try {
this.stmt = con.prepareStatement(sql.toString());
this.stmt.setInt(1, id);
this.stmt.setString(2, name);
this.stmt.setString(3, kana);
this.stmt.setString(4, mail);
this.stmt.setString(5, pass);
this.stmt.setInt(6, depId);
this.stmt.executeUpdate();
} finally {
DbUtil.closeStatement​(this.stmt);
}
this.stmt = con.prepareStatement(sql.toString());
this.stmt.setString(1, name);
this.stmt.setString(2, kana);
this.stmt.setString(3, mail);
this.stmt.setString(4, pass);
this.stmt.setInt(5, depId);
this.stmt.executeUpdate();
} finally {
DbUtil.closeStatement​(this.stmt);
}
}
public void empUpdate​(int id, java.lang.String name, java.lang.String kana, java.lang.String mail,
java.lang.String pass, int depId)
throws java.lang.ClassNotFoundException, java.sql.SQLException, java.lang.NumberFormatException {
StringBuilder sql = new StringBuilder();
sql.append(" UPDATE ");
sql.append(TBL_NAME);
sql.append(" SET ");
sql.append(" nm_employee = ?, kn_employee = ?, mail_address = ?, password = ?, id_department = ? ");
sql.append(" WHERE id_employee = ? ");
try {
this.stmt = con.prepareStatement(sql.toString());
this.stmt.setString(1, name);
this.stmt.setString(2, kana);
this.stmt.setString(3, mail);
this.stmt.setString(4, pass);
this.stmt.setInt(5, depId);
this.stmt.setInt(6, id);
this.stmt.executeUpdate();
} finally {
DbUtil.closeStatement​(this.stmt);
}
}
}

View File

@@ -110,22 +110,20 @@ public class Main {
);
}
} finally {
DbUtil.closeConnection​(empDao.con);
}
}
public static void empInsert()
throws java.lang.NumberFormatException, java.lang.ClassNotFoundException, java.sql.SQLException {
throws java.lang.NumberFormatException, java.lang.ClassNotFoundException, java.sql.SQLException {
//List<EmployeeDTO> empList = new ArrayList<>();
Connection con = DbUtil.getConnection();
EmployeeDAO empDao = new EmployeeDAO(con);
try {
String name = inputCheck("社員名", false);
String kana = inputCheck("フリガナ", false);
String mail = inputCheck("メールアドレス", false);
@@ -143,35 +141,39 @@ public class Main {
}
}
public static void empUpdate() throws java.lang.NumberFormatException, java.lang.ClassNotFoundException, java.sql.SQLException{
public static void empUpdate()
throws java.lang.NumberFormatException, java.lang.ClassNotFoundException, java.sql.SQLException {
Connection con = DbUtil.getConnection();
EmployeeDAO empDao = new EmployeeDAO(con);
try {
String idstr = inputCheck("ID",true);
String idstr = inputCheck("ID", true);
int id = Integer.parseInt(idstr);
List<EmployeeDTO> checkList = empDao.selectById​(id);
if (checkList.size() == 0) {
System.out.println("入力された値で情報がみつかりませんでした");
return;
}
String name = inputCheck("社員名", false);
String kana = inputCheck("フリガナ", false);
String mail = inputCheck("メールアドレス", false);
String pass = inputCheck("パスワード", false);
String depIdstr = inputCheck("部署ID", true);
int id = Integer.parseInt(idstr);
int depId = Integer.parseInt(depIdstr);
System.out.println("更新が完了しました");
empDao.empUpdate​(id, name, kana, mail, pass, depId);
empDao.empUpdate​(id,name, kana, mail, pass, depId);
System.out.println("更新が完了しました");
} finally {
DbUtil.closeConnection​(empDao.con);
}
}
public static void empDelete() throws ClassNotFoundException, SQLException {