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(); - + } + } }