1 Commits

Author SHA1 Message Date
897a006918 1段階目です。 2026-09-29 17:21:43 +09:00
8 changed files with 27 additions and 49 deletions

1
.gitignore vendored
View File

@@ -1 +0,0 @@
/.metadata/

View File

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>em-jdbc</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>src</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -1 +0,0 @@
/EmployeeDAO.class

View File

@@ -1 +0,0 @@
/Main.class

View File

@@ -1 +0,0 @@
/DbUtil.class

View File

@@ -44,10 +44,18 @@ public class DbUtil {
* 生成されたConnectionを返却する
* ※Connection生成には上記の定数を活用してください
*/
public static Connection getConnection() throws SQLException {
//データベースへの接続
con = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
return con;
public static Connection getConnection() throws ClassNotFoundException, SQLException {
try {
Class.forName(DB_DRIVER);
return DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
} catch (ClassNotFoundException e) {
System.out.println();
throw e;
} catch (SQLException e) {
System.out.println();
throw e;
}
}
/*
@@ -59,10 +67,13 @@ public class DbUtil {
* 例外 :SQLException
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
*/
public static void closeStatement(PreparedStatement stmt) throws SQLException {
//nullチェック
public static void closeStatement(PreparedStatement stmt) {
if (stmt != null) {
stmt.close();
try {
stmt.close();
} catch (SQLException e) {
System.out.println();
}
}
}
@@ -75,11 +86,16 @@ public class DbUtil {
* 例外 :SQLException
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
*/
public static void closeConnection(Connection con) throws SQLException {
//nullチェック
public static void closeConnection(Connection con) {
if (con != null) {
con.close();
try {
if (!con.isClosed()) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}