diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..25cd837
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
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..5cc4285 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.main.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,10 +61,12 @@ public class EmployeeDAO {
this.stmt = con.prepareStatement(sql.toString());
rs = stmt.executeQuery();
while (rs.next()) {
+ EmployeeDTO emdto = new EmployeeDTO();
+ emdto.set
rtnList.add(rs.getString(NM_EMPLOYEE));
}
} finally {
- DbUtil.closeStatement(this.stmt);
+ DbUtil.closeStatement();
}
return rtnList;
}
diff --git a/src/com/rhizome/example/dto/EmployeeDTO.java b/src/com/rhizome/example/dto/EmployeeDTO.java
new file mode 100644
index 0000000..efa0ff7
--- /dev/null
+++ b/src/com/rhizome/example/dto/EmployeeDTO.java
@@ -0,0 +1,38 @@
+package com.rhizome.example.dto;
+
+public class EmployeeDTO {
+
+ //Employeeテーブルのカラム分のフィールド
+ private static final String TBL_NAME = "employee";
+ private static final String ID_EMPLOYEE = "id_employee";
+ private static final String NM_EMPLOYEE = "nm_employee";
+ private static final String KN_EMPLOYEE = "kn_employee";
+ private static final String MAIL_ADDRESS = "mail_address";
+ private static final String PASSWORD = "password";
+ private static final String ID_DEPARTMENT = "id_department";
+ public static String getTblName() {
+ return TBL_NAME;
+ }
+ public static String getIdEmployee() {
+ return ID_EMPLOYEE;
+ }
+ public static String getNmEmployee() {
+ return NM_EMPLOYEE;
+ }
+ public static String getKnEmployee() {
+ return KN_EMPLOYEE;
+ }
+ public static String getMailAddress() {
+ return MAIL_ADDRESS;
+ }
+ public static String getPassword() {
+ return PASSWORD;
+ }
+ public static String getIdDepartment() {
+ return ID_DEPARTMENT;
+ }
+
+
+
+
+}
\ No newline at end of file
diff --git a/src/com/rhizome/example/main/Main.java b/src/com/rhizome/example/main/Main.java
index 14fb220..ab31d9c 100644
--- a/src/com/rhizome/example/main/Main.java
+++ b/src/com/rhizome/example/main/Main.java
@@ -93,7 +93,7 @@ public class Main {
System.out.println(emp);
}
} finally {
- DbUtil.closeConnection(empDao.con);
+ DbUtil.closeConnection();
}
}
diff --git a/src/com/rhizome/example/util/DbUtil.java b/src/com/rhizome/example/util/DbUtil.java
index d2bb82e..1b49e1d 100644
--- a/src/com/rhizome/example/util/DbUtil.java
+++ b/src/com/rhizome/example/util/DbUtil.java
@@ -1,6 +1,10 @@
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 +45,26 @@ public class DbUtil {
* 生成されたConnectionを返却する
* ※Connection生成には上記の定数を活用してください
*/
+ //DB接続用メソッドを作成する
+ public static Connection getConnection() throws ClassNotFoundException {
+ //データベースの接続オブジェクトを初期化
+ Connection con = null;
+ // JDBCドライバの読み込み
+ Class.forName("com.mysql.cj.jdbc.Driver");
+ // Connectionの生成
+ try {
+ con = DriverManager.getConnection(
+ "jdbc:mysql://127.0.0.1:3306/rezodb" // データベース
+ , "rezouser" // ユーザ
+ , "Rezo_0000" // パスワード
+ );
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return con;
+ }
+
/*
* TODO 以下の仕様でメソッドを作成してください。
@@ -52,7 +75,15 @@ public class DbUtil {
* 例外 :SQLException
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
*/
-
+ public static void closeStatement() {
+ PreparedStatement stmt = null;
+ try {
+ if (stmt != null) stmt.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ }
/*
* TODO 以下の仕様でメソッドを作成してください。
@@ -63,6 +94,12 @@ public class DbUtil {
* 例外 :SQLException
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
*/
-
+ public static void closeConnection() {
+ try {
+ if (con != null) con.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
}