From 1c04363bb712d0ba2c5a014c4167310b66071cae Mon Sep 17 00:00:00 2001
From: m-endo <26-s-i-tm-nets@it-college.jp>
Date: Wed, 30 Sep 2026 13:37:36 +0900
Subject: [PATCH] =?UTF-8?q?2=E6=AE=B5=E9=9A=8E=E7=9B=AE=E5=AE=8C=E4=BA=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.classpath | 8 +++
.gitignore | 1 +
.project | 23 +++++++
.settings/.jsdtscope | 7 +++
...rg.eclipse.wst.jsdt.ui.superType.container | 1 +
.../org.eclipse.wst.jsdt.ui.superType.name | 1 +
src/com/rhizome/example/dao/EmployeeDAO.java | 15 ++++-
src/com/rhizome/example/dto/EmployeeDTO.java | 61 +++++++++++++++++++
src/com/rhizome/example/main/Main.java | 5 +-
src/com/rhizome/example/util/DbUtil.java | 23 ++++++-
10 files changed, 137 insertions(+), 8 deletions(-)
create mode 100644 .classpath
create mode 100644 .gitignore
create mode 100644 .project
create mode 100644 .settings/.jsdtscope
create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.container
create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.name
create mode 100644 src/com/rhizome/example/dto/EmployeeDTO.java
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..8ddd4c7
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/.project b/.project
new file mode 100644
index 0000000..ccaa13e
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ em-jdbc
+
+
+
+
+
+ org.eclipse.wst.validation.validationbuilder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.wst.jsdt.core.jsNature
+
+
diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope
new file mode 100644
index 0000000..cca691f
--- /dev/null
+++ b/.settings/.jsdtscope
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container
new file mode 100644
index 0000000..49c8cd4
--- /dev/null
+++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container
@@ -0,0 +1 @@
+org.eclipse.wst.jsdt.launching.JRE_CONTAINER
\ No newline at end of file
diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name
new file mode 100644
index 0000000..11006e2
--- /dev/null
+++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name
@@ -0,0 +1 @@
+Global
\ No newline at end of file
diff --git a/src/com/rhizome/example/dao/EmployeeDAO.java b/src/com/rhizome/example/dao/EmployeeDAO.java
index ef63c49..a37140a 100644
--- a/src/com/rhizome/example/dao/EmployeeDAO.java
+++ b/src/com/rhizome/example/dao/EmployeeDAO.java
@@ -13,6 +13,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import com.rhizome.example.dto.EmployeeDTO;
import com.rhizome.example.util.DbUtil;
public class EmployeeDAO {
@@ -48,8 +49,8 @@ public class EmployeeDAO {
* @throws SQLException
* @throws ClassNotFoundException
*/
- public List selectAll() throws SQLException, ClassNotFoundException {
- List rtnList = new ArrayList<>();
+ public List selectAll() throws SQLException, ClassNotFoundException {
+ List rtnList = new ArrayList<>();
StringBuilder sql = new StringBuilder();
sql.append(" SELECT ");
sql.append(" " + "*");
@@ -60,7 +61,15 @@ public class EmployeeDAO {
this.stmt = con.prepareStatement(sql.toString());
rs = stmt.executeQuery();
while (rs.next()) {
- rtnList.add(rs.getString(NM_EMPLOYEE));
+ //インスタンス生成
+ 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"));
+ rtnList.add(dto);
}
} finally {
DbUtil.closeStatement(this.stmt);
diff --git a/src/com/rhizome/example/dto/EmployeeDTO.java b/src/com/rhizome/example/dto/EmployeeDTO.java
new file mode 100644
index 0000000..addcd96
--- /dev/null
+++ b/src/com/rhizome/example/dto/EmployeeDTO.java
@@ -0,0 +1,61 @@
+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
+
+ //getter/setter
+ public Integer getId_employee() {
+ return id_employee;
+ }
+
+ public void setId_employee(Integer id_employee) {
+ this.id_employee = id_employee;
+ }
+
+ public String getNm_employee() {
+ return nm_employee;
+ }
+
+ public void setNm_employee(String nm_employee) {
+ this.nm_employee = nm_employee;
+ }
+
+ public String getKn_employee() {
+ return kn_employee;
+ }
+
+ public void setKn_employee(String kn_employee) {
+ this.kn_employee = kn_employee;
+ }
+
+ public String getMail_address() {
+ return mail_address;
+ }
+
+ public void setMail_address(String mail_address) {
+ this.mail_address = mail_address;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public Integer getId_department() {
+ return id_department;
+ }
+
+ public void setId_department(Integer id_department) {
+ this.id_department = id_department;
+ }
+
+}
diff --git a/src/com/rhizome/example/main/Main.java b/src/com/rhizome/example/main/Main.java
index 14fb220..a20592f 100644
--- a/src/com/rhizome/example/main/Main.java
+++ b/src/com/rhizome/example/main/Main.java
@@ -7,6 +7,7 @@ import java.util.List;
import java.util.Scanner;
import com.rhizome.example.dao.EmployeeDAO;
+import com.rhizome.example.dto.EmployeeDTO;
import com.rhizome.example.util.DbUtil;
/**
@@ -76,7 +77,7 @@ public class Main {
* @throws SQLException
*/
public static void empSelect() throws ClassNotFoundException, SQLException {
- List empList = new ArrayList<>();
+ List empList = new ArrayList<>();
Connection con = DbUtil.getConnection();
EmployeeDAO empDao = new EmployeeDAO(con);
System.out.println("1:全検索 2:条件検索 それ以外:戻る");
@@ -89,7 +90,7 @@ public class Main {
default:
return;
}
- for (String emp : empList) {
+ for (EmployeeDTO emp : empList) {
System.out.println(emp);
}
} finally {
diff --git a/src/com/rhizome/example/util/DbUtil.java b/src/com/rhizome/example/util/DbUtil.java
index d2bb82e..0ec2661 100644
--- a/src/com/rhizome/example/util/DbUtil.java
+++ b/src/com/rhizome/example/util/DbUtil.java
@@ -1,6 +1,9 @@
package com.rhizome.example.util;
import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
public class DbUtil {
// 定数定義(共通)
@@ -41,7 +44,11 @@ public class DbUtil {
* 生成されたConnectionを返却する
* ※Connection生成には上記の定数を活用してください
*/
-
+ public static Connection getConnection() throws SQLException {
+ //データベースへの接続
+ con = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
+ return con;
+ }
/*
* TODO 以下の仕様でメソッドを作成してください。
@@ -52,7 +59,12 @@ public class DbUtil {
* 例外 :SQLException
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
*/
-
+ public static void closeStatement(PreparedStatement stmt) throws SQLException {
+ //nullチェック
+ if (stmt != null) {
+ stmt.close();
+ }
+ }
/*
* TODO 以下の仕様でメソッドを作成してください。
@@ -63,6 +75,11 @@ public class DbUtil {
* 例外 :SQLException
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
*/
+ public static void closeConnection(Connection con) throws SQLException {
+ //nullチェック
+ if (con != null) {
+ con.close();
-
+ }
+ }
}