From bb5df7baada6d59431026c3f139e5d5998cb5084 Mon Sep 17 00:00:00 2001 From: y-ogawa <26-y-ogawa-tmn@it-college.co.jp> Date: Wed, 30 Sep 2026 11:26:04 +0900 Subject: [PATCH] =?UTF-8?q?1=E6=AE=B5=E9=9A=8E=E7=9B=AE=E7=B5=82=E4=BA=86?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= 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 | 2 +- src/com/rhizome/example/util/DbUtil.java | 22 +++++++++++++++--- 8 files changed, 61 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 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..eff7c33 100644 --- a/src/com/rhizome/example/dao/EmployeeDAO.java +++ b/src/com/rhizome/example/dao/EmployeeDAO.java @@ -63,7 +63,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/util/DbUtil.java b/src/com/rhizome/example/util/DbUtil.java index d2bb82e..f695f82 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 以下の仕様でメソッドを作成してください。 @@ -53,6 +60,12 @@ public class DbUtil { * 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする */ + public static void closestatement(PreparedStatement stmt) throws SQLException { + if (!stmt.equals(null)) { + //DBステートメントを閉じる + stmt.close(); + } + } /* * TODO 以下の仕様でメソッドを作成してください。 @@ -63,6 +76,9 @@ public class DbUtil { * 例外 :SQLException * 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する */ - - + public static void closeConnection(Connection con) throws SQLException { + if (!con.equals(null)) { + con.close(); + } + } }