段階4完了
This commit is contained in:
@@ -114,4 +114,24 @@ public class EmployeeDAO {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void empDelete(int id) throws SQLException {
|
||||||
|
StringBuilder sql = new StringBuilder();
|
||||||
|
//社員テーブルから指定された社員IDに一致するデータを取得
|
||||||
|
sql.append(" DELETE ");
|
||||||
|
sql.append(" " + "*");
|
||||||
|
sql.append(" FROM ");
|
||||||
|
sql.append(" " + TBL_NAME);
|
||||||
|
sql.append(" WHERE ");
|
||||||
|
sql.append(" " + ID_EMPLOYEE);
|
||||||
|
sql.append(" = ");
|
||||||
|
sql.append(" " + id);
|
||||||
|
try {
|
||||||
|
this.stmt = con.prepareStatement(sql.toString());
|
||||||
|
this.stmt.executeUpdate();
|
||||||
|
System.out.println("削除が完了しました");
|
||||||
|
} finally {
|
||||||
|
DbUtil.closeStatement(this.stmt);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ public class Main {
|
|||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public void start() throws ClassNotFoundException, SQLException {
|
public void start() throws ClassNotFoundException, SQLException {
|
||||||
|
Connection con = DbUtil.getConnection();
|
||||||
|
EmployeeDAO empDao = new EmployeeDAO(con);
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("現在のメンテナンス対象テーブル:" + targetTableName(tblFlg));
|
System.out.println("現在のメンテナンス対象テーブル:" + targetTableName(tblFlg));
|
||||||
System.out.println("1:検索 2:登録 3:更新 4:削除 9:テーブル切替 0:終了");
|
System.out.println("1:検索 2:登録 3:更新 4:削除 9:テーブル切替 0:終了");
|
||||||
@@ -58,6 +60,7 @@ public class Main {
|
|||||||
case "3":
|
case "3":
|
||||||
break;
|
break;
|
||||||
case "4":
|
case "4":
|
||||||
|
empDelete();
|
||||||
break;
|
break;
|
||||||
case "9":
|
case "9":
|
||||||
return;
|
return;
|
||||||
@@ -70,6 +73,30 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void empDelete() throws SQLException {
|
||||||
|
Connection con = DbUtil.getConnection();
|
||||||
|
EmployeeDAO empDao = new EmployeeDAO(con);
|
||||||
|
try {
|
||||||
|
String strId = inputCheck("ID", true);
|
||||||
|
int id = Integer.parseInt(strId);
|
||||||
|
List<EmployeeDTO> empList = empDao.selectByld(id);
|
||||||
|
if (empList.isEmpty()) {
|
||||||
|
} else {
|
||||||
|
System.out.println("指定されたIDの情報を削除します? Y/y");
|
||||||
|
System.out.println("Y/y以外の入力であればキャンセル");
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
String str = sc.nextLine();
|
||||||
|
if (str.equals("Y") || str.equals("y")) {
|
||||||
|
empDao.empDelete(id);
|
||||||
|
} else {
|
||||||
|
System.out.println("キャンセルしました");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
DbUtil.closeConnection(empDao.con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 社員テーブルから情報を検索する
|
* 社員テーブルから情報を検索する
|
||||||
*
|
*
|
||||||
@@ -131,7 +158,7 @@ public class Main {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String inputCheck(String titleName, boolean flg) {
|
public static String inputCheck(String titleName, boolean flg) {
|
||||||
String str = null;
|
String str;
|
||||||
while (true) {
|
while (true) {
|
||||||
System.out.println(titleName + "を入力してください");
|
System.out.println(titleName + "を入力してください");
|
||||||
str = sc.nextLine();
|
str = sc.nextLine();
|
||||||
|
|||||||
Reference in New Issue
Block a user