From 7cb48440b0bb79b151415b2525cf503c84ffe575 Mon Sep 17 00:00:00 2001 From: m-endo <26-s-i-tm-nets@it-college.jp> Date: Wed, 30 Sep 2026 11:14:27 +0900 Subject: [PATCH] =?UTF-8?q?1=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 --- .gitignore | 1 + .project | 11 +++++++++++ src/.classpath | 6 ++++++ src/.project | 17 +++++++++++++++++ src/com/rhizome/example/dao/.gitignore | 1 + src/com/rhizome/example/main/.gitignore | 1 + src/com/rhizome/example/util/.gitignore | 1 + src/com/rhizome/example/util/DbUtil.java | 23 ++++++++++++++++++++--- 8 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 .project create mode 100644 src/.classpath create mode 100644 src/.project create mode 100644 src/com/rhizome/example/dao/.gitignore create mode 100644 src/com/rhizome/example/main/.gitignore create mode 100644 src/com/rhizome/example/util/.gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e10e727 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.metadata/ diff --git a/.project b/.project new file mode 100644 index 0000000..f13516c --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + em-jdbc + + + + + + + + diff --git a/src/.classpath b/src/.classpath new file mode 100644 index 0000000..3f3893a --- /dev/null +++ b/src/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/.project b/src/.project new file mode 100644 index 0000000..0f6f6a7 --- /dev/null +++ b/src/.project @@ -0,0 +1,17 @@ + + + src + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/src/com/rhizome/example/dao/.gitignore b/src/com/rhizome/example/dao/.gitignore new file mode 100644 index 0000000..d9ddd24 --- /dev/null +++ b/src/com/rhizome/example/dao/.gitignore @@ -0,0 +1 @@ +/EmployeeDAO.class diff --git a/src/com/rhizome/example/main/.gitignore b/src/com/rhizome/example/main/.gitignore new file mode 100644 index 0000000..a66c73a --- /dev/null +++ b/src/com/rhizome/example/main/.gitignore @@ -0,0 +1 @@ +/Main.class diff --git a/src/com/rhizome/example/util/.gitignore b/src/com/rhizome/example/util/.gitignore new file mode 100644 index 0000000..d5d39e4 --- /dev/null +++ b/src/com/rhizome/example/util/.gitignore @@ -0,0 +1 @@ +/DbUtil.class 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(); - + } + } }