From df7972c662b915f1f8d204b8bf06aba921995e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=93=A6=E3=80=80=E6=98=B4=E4=B8=96?= <26-k-kawara-rootship@it-college.co.jp> Date: Wed, 28 Oct 2026 16:58:58 +0900 Subject: [PATCH] =?UTF-8?q?1=E6=97=A5=E7=9B=AE=E3=80=802=E6=AE=B5=E9=9A=8E?= =?UTF-8?q?=E7=9B=AE=E3=81=BE=E3=81=A7?= 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 | 7 +++--- src/com/rhizome/example/dto/EmployeeDTO.java | 7 ++++++ src/com/rhizome/example/main/Main.java | 2 +- src/com/rhizome/example/util/DbUtil.java | 20 ++++++++++++++++ 10 files changed, 73 insertions(+), 4 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..2e9776e --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + em-jdbc + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.wst.jsdt.core.jsNature + org.eclipse.jdt.core.javanature + + 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..3272754 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(" " + "*"); @@ -63,7 +64,7 @@ public class EmployeeDAO { rtnList.add(rs.getString(NM_EMPLOYEE)); } } finally { - DbUtil.closeStatement(this.stmt); + DbUtil.closeStatement​(this.stmt); } 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..acfb518 --- /dev/null +++ b/src/com/rhizome/example/dto/EmployeeDTO.java @@ -0,0 +1,7 @@ +package com.rhizome.example.dto; + +public class EmployeeDTO { + + + +} diff --git a/src/com/rhizome/example/main/Main.java b/src/com/rhizome/example/main/Main.java index 14fb220..8f50fc9 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​(empDao.con); } } diff --git a/src/com/rhizome/example/util/DbUtil.java b/src/com/rhizome/example/util/DbUtil.java index d2bb82e..a3d3b56 100644 --- a/src/com/rhizome/example/util/DbUtil.java +++ b/src/com/rhizome/example/util/DbUtil.java @@ -1,6 +1,7 @@ package com.rhizome.example.util; import java.sql.Connection; +import java.sql.DriverManager; public class DbUtil { // 定数定義(共通) @@ -42,6 +43,10 @@ public class DbUtil { * ※Connection生成には上記の定数を活用してください */ + public static java.sql.Connection getConnection() throws java.lang.ClassNotFoundException, java.sql.SQLException { + con = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS); + return con; + } /* * TODO 以下の仕様でメソッドを作成してください。 @@ -53,6 +58,11 @@ public class DbUtil { * 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする */ + public static void closeStatement​(java.sql.PreparedStatement stmt) throws java.sql.SQLException { + if (stmt != null) { + stmt.close(); + } + } /* * TODO 以下の仕様でメソッドを作成してください。 @@ -64,5 +74,15 @@ public class DbUtil { * 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する */ + //public static void closeConnection(Connection con) throws SQLException { + //if (con != null) { + //con.close(); + //} + // + + public static void closeConnection​(java.sql.Connection con) throws java.sql.SQLException { + if (con != null) + con.close(); + } }