Stept 1
This commit is contained in:
@@ -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 {
|
||||
// 定数定義(共通)
|
||||
@@ -39,9 +42,18 @@ public class DbUtil {
|
||||
* 例外 :ClassNotFoundException, SQLException
|
||||
* 処理 :JDBCドライバを読み込み後、DB接続する。
|
||||
* 生成されたConnectionを返却する
|
||||
* ※Connection生成には上記の定数を活用してください
|
||||
* ※Connection生成には上記の定数を活用してくださ
|
||||
*/
|
||||
|
||||
public static Connection getConnection() throws ClassNotFoundException, SQLException {
|
||||
//connection is null or not null and create new
|
||||
if (con == null || con.isClosed()) {
|
||||
Class.forName(DB_DRIVER);
|
||||
con = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
|
||||
}
|
||||
return con;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* TODO 以下の仕様でメソッドを作成してください。
|
||||
@@ -52,7 +64,13 @@ public class DbUtil {
|
||||
* 例外 :SQLException
|
||||
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
|
||||
*/
|
||||
public static void closeStatement(PreparedStatement stmt) throws SQLException {
|
||||
if (stmt != null) {
|
||||
stmt.close();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO 以下の仕様でメソッドを作成してください。
|
||||
@@ -63,6 +81,11 @@ public class DbUtil {
|
||||
* 例外 :SQLException
|
||||
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
|
||||
*/
|
||||
public static void closeConnection(Connection con) throws SQLException {
|
||||
if(con != null) {
|
||||
con.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user