必須段階実装完了
This commit is contained in:
@@ -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 ");
|
||||
@@ -129,7 +130,8 @@ public class EmployeeDAO {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -153,21 +155,25 @@ public class EmployeeDAO {
|
||||
}
|
||||
}
|
||||
|
||||
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{
|
||||
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(" 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.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.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();
|
||||
|
||||
|
||||
@@ -124,8 +124,6 @@ public class Main {
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
||||
String name = inputCheck("社員名", false);
|
||||
String kana = inputCheck("フリガナ", false);
|
||||
String mail = inputCheck("メールアドレス", false);
|
||||
@@ -144,34 +142,38 @@ 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);
|
||||
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);
|
||||
|
||||
System.out.println("更新が完了しました");
|
||||
|
||||
} finally {
|
||||
DbUtil.closeConnection(empDao.con);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void empDelete() throws ClassNotFoundException, SQLException {
|
||||
|
||||
Reference in New Issue
Block a user