Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c04363bb7 |
@@ -61,6 +61,7 @@ public class EmployeeDAO {
|
||||
this.stmt = con.prepareStatement(sql.toString());
|
||||
rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
//インスタンス生成
|
||||
EmployeeDTO dto = new EmployeeDTO();
|
||||
dto.setId_employee(rs.getInt("id_employee"));
|
||||
dto.setNm_employee(rs.getString("nm_employee"));
|
||||
@@ -71,37 +72,9 @@ public class EmployeeDAO {
|
||||
rtnList.add(dto);
|
||||
}
|
||||
} finally {
|
||||
DbUtil.closestatement(this.stmt);
|
||||
DbUtil.closeStatement(this.stmt);
|
||||
}
|
||||
return rtnList;
|
||||
}
|
||||
|
||||
public List<EmployeeDTO> selectById(int id_employee) throws SQLException, ClassNotFoundException {
|
||||
List<EmployeeDTO> rtnList2 = new ArrayList<>();
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append(" SELECT ");
|
||||
sql.append(" " + "*");
|
||||
sql.append(" FROM ");
|
||||
sql.append(" " + TBL_NAME);
|
||||
sql.append(" WHERE " + ID_EMPLOYEE+ "=?");
|
||||
try {
|
||||
|
||||
this.stmt = con.prepareStatement(sql.toString());
|
||||
rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
EmployeeDTO dto = new EmployeeDTO();
|
||||
dto.setId_employee(rs.getInt("id_employee"));
|
||||
dto.setNm_employee(rs.getString("nm_employee"));
|
||||
dto.setKn_employee(rs.getString("kn_employee"));
|
||||
dto.setMail_address(rs.getString("mail_address"));
|
||||
dto.setPassword(rs.getString("password"));
|
||||
dto.setId_department(rs.getInt("id_department"));
|
||||
rtnList2.add(dto);
|
||||
}
|
||||
} finally {
|
||||
DbUtil.closestatement(this.stmt);
|
||||
}
|
||||
return rtnList2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.rhizome.example.dto;
|
||||
|
||||
public class EmployeeDTO {
|
||||
//フィールド宣言
|
||||
private Integer id_employee;//社員ID
|
||||
private String nm_employee;//社員名
|
||||
private String kn_employee;//社員名カナ
|
||||
private String mail_address;//メールアドレス
|
||||
private String password;//パスワード
|
||||
private Integer id_department;//部署ID
|
||||
|
||||
private Integer id_employee;
|
||||
private String nm_employee;
|
||||
private String kn_employee;
|
||||
private String mail_address;
|
||||
private String password;
|
||||
private Integer id_department;
|
||||
|
||||
//getter/setter
|
||||
public Integer getId_employee() {
|
||||
return id_employee;
|
||||
}
|
||||
@@ -57,13 +58,4 @@ public class EmployeeDTO {
|
||||
this.id_department = id_department;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return id_employee + "\t"
|
||||
+ nm_employee + "\t"
|
||||
+ kn_employee + "\t"
|
||||
+ mail_address + "\t"
|
||||
+ password + "\t"
|
||||
+ id_department;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,11 +87,6 @@ public class Main {
|
||||
case "1":
|
||||
empList = empDao.selectAll();
|
||||
break;
|
||||
case "2":
|
||||
System.out.println("IDを入力してください");
|
||||
|
||||
empList = empDao.selectById(tblFlg);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class DbUtil {
|
||||
* ※Connection生成には上記の定数を活用してください
|
||||
*/
|
||||
public static Connection getConnection() throws SQLException {
|
||||
//データベースの接続
|
||||
//データベースへの接続
|
||||
con = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
|
||||
return con;
|
||||
}
|
||||
@@ -59,10 +59,9 @@ public class DbUtil {
|
||||
* 例外 :SQLException
|
||||
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
|
||||
*/
|
||||
|
||||
public static void closestatement(PreparedStatement stmt) throws SQLException {
|
||||
if (!stmt.equals(null)) {
|
||||
//DBステートメントを閉じる
|
||||
public static void closeStatement(PreparedStatement stmt) throws SQLException {
|
||||
//nullチェック
|
||||
if (stmt != null) {
|
||||
stmt.close();
|
||||
}
|
||||
}
|
||||
@@ -77,8 +76,10 @@ public class DbUtil {
|
||||
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
|
||||
*/
|
||||
public static void closeConnection(Connection con) throws SQLException {
|
||||
if (!con.equals(null)) {
|
||||
//nullチェック
|
||||
if (con != null) {
|
||||
con.close();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user