Stept 5 INSERT

This commit is contained in:
2026-09-30 14:51:54 +09:00
parent a5533aeb77
commit 9e7d1e06ae
2 changed files with 56 additions and 11 deletions

View File

@@ -122,14 +122,14 @@ public class EmployeeDAO {
} }
return rtnList; return rtnList;
} }
//Delete method
public void empDelete(int empId) throws ClassNotFoundException, SQLException { public void empDelete(int empId) throws ClassNotFoundException, SQLException {
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.append(" DELETE FROM "); sql.append(" DELETE FROM ");
sql.append(" " + TBL_NAME); sql.append(" " + TBL_NAME);
sql.append(" WHERE "); sql.append(" WHERE ");
sql.append(" " + ID_EMPLOYEE + " = ? "); sql.append(" " + ID_EMPLOYEE + " = ? ");
//for check
try { try {
this.stmt = con.prepareStatement(sql.toString()); this.stmt = con.prepareStatement(sql.toString());
this.stmt.setInt(1, empId); this.stmt.setInt(1, empId);
@@ -139,4 +139,32 @@ public class EmployeeDAO {
} }
} }
public void empInsert (String nmemp, String knname,String mail, String pw, int deptId) throws ClassNotFoundException, SQLException{
StringBuilder sql = new StringBuilder();
sql.append("INSERT INTO");
sql.append(" " + TBL_NAME);
sql.append(" ( ");
sql.append(" " + NM_EMPLOYEE + ",");
sql.append(" " + KN_EMPLOYEE + ",");
sql.append(" " + MAIL_ADDRESS + ",");
sql.append(" " + PASSWORD + ",");
sql.append(" " + ID_DEPARTMENT);
sql.append(" ) ");
sql.append(" VALUES (?, ?, ?, ?, ?) ");
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.executeUpdate();
} finally {
DbUtil.closeStatement(this.stmt);
}
}
} }

View File

@@ -54,6 +54,7 @@ public class Main {
empSelect(); empSelect();
break; break;
case "2": case "2":
empInsert();
break; break;
case "3": case "3":
break; break;
@@ -71,6 +72,30 @@ public class Main {
} }
} }
public static void empInsert() throws ClassNotFoundException, SQLException {
Connection con = DbUtil.getConnection();
EmployeeDAO empDao = new EmployeeDAO(con);
try {
// အချက်အလက်များ အသီးသီး တောင်းခံခြင်း (inputCheck ကို သုံးပါ)
String name = inputCheck("社員名", false);
String kana = inputCheck("フリガナ", false);
String mail = inputCheck("メールアドレス", false);
String pass = inputCheck("パスワード", false);
// 部署ID အတွက် Numerical Check ဖြစ်သည့် true ထည့်ပါမည်
String strDeptId = inputCheck("部署ID", true);
int deptId = Integer.parseInt(strDeptId);
// DB ထဲသို့ ထည့်သွင်းခြင်း
empDao.empInsert(name, kana, mail, pass, deptId);
System.out.println("登録が完了しました");
} finally {
DbUtil.closeConnection(empDao.con);
}
}
/** /**
* 社員テーブルから情報を検索する * 社員テーブルから情報を検索する
* *
@@ -95,15 +120,7 @@ public class Main {
String strId = inputCheck("ID", true); String strId = inputCheck("ID", true);
int id = Integer.parseInt(strId); int id = Integer.parseInt(strId);
empList = empDao.selectById(id); empList = empDao.selectById(id);
break; ;
case "3":
break;
case "4":
// String empId = inputCheck("ID", true);
// int empID = Integer.parseInt(empId);
empDelete();
break;
default: default:
return; return;