Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b4f52cbc55 | |||
| f5ef9d86f6 | |||
| 54565e4472 | |||
| da3b79b06b | |||
| fb8d2c0b1c |
@@ -53,28 +53,22 @@ public class EmployeeDAO {
|
|||||||
List<EmployeeDTO> rtnList = new ArrayList<>();
|
List<EmployeeDTO> rtnList = new ArrayList<>();
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
sql.append(" SELECT ");
|
sql.append(" SELECT ");
|
||||||
sql.append(" " + ID_EMPLOYEE + ",");
|
sql.append(" " + "*");
|
||||||
sql.append(" " + NM_EMPLOYEE + ",");
|
|
||||||
sql.append(" " + KN_EMPLOYEE + ",");
|
|
||||||
sql.append(" " + MAIL_ADDRESS + ",");
|
|
||||||
sql.append(" " + PASSWORD + ",");
|
|
||||||
sql.append(" " + ID_DEPARTMENT);
|
|
||||||
sql.append(" FROM ");
|
sql.append(" FROM ");
|
||||||
sql.append(" " + TBL_NAME);
|
sql.append(" " + TBL_NAME);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
this.stmt = con.prepareStatement(sql.toString());
|
this.stmt = con.prepareStatement(sql.toString());
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
//DBのカラムをリストに追加
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
EmployeeDTO dto = new EmployeeDTO();
|
EmployeeDTO dto = new EmployeeDTO();
|
||||||
dto.setIdEmployee(rs.getInt(ID_EMPLOYEE));
|
dto.setEmpid(rs.getInt(ID_EMPLOYEE));
|
||||||
dto.setNmEmployee(rs.getString(NM_EMPLOYEE));
|
dto.setName(rs.getString(NM_EMPLOYEE));
|
||||||
dto.setKnEmployee(rs.getString(KN_EMPLOYEE));
|
dto.setKana(rs.getString(KN_EMPLOYEE));
|
||||||
dto.setMailAddress(rs.getString(MAIL_ADDRESS));
|
dto.setMail(rs.getString(MAIL_ADDRESS));
|
||||||
dto.setPassword(rs.getString(PASSWORD));
|
dto.setPass(rs.getString(PASSWORD));
|
||||||
dto.setIdDepartment(rs.getInt(ID_DEPARTMENT));
|
dto.setDepid(rs.getInt(ID_DEPARTMENT));
|
||||||
|
|
||||||
// dto ကို List ထဲသို့ ထည့်ရပါမည်
|
|
||||||
rtnList.add(dto);
|
rtnList.add(dto);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -83,117 +77,65 @@ public class EmployeeDAO {
|
|||||||
return rtnList;
|
return rtnList;
|
||||||
}
|
}
|
||||||
|
|
||||||
//use selectById make the method
|
public List<EmployeeDTO> selectByld(int id) throws SQLException {
|
||||||
public List<EmployeeDTO> selectById(int empId) throws SQLException, ClassNotFoundException {
|
|
||||||
//calling to DTO and new inout array
|
|
||||||
List<EmployeeDTO> rtnList = new ArrayList<>();
|
List<EmployeeDTO> rtnList = new ArrayList<>();
|
||||||
//(StringBuilder) ကို သုံးခြင်းသည် Code များကို ဖတ်ရလွယ်ကူစေရန်၊ ပြင်ဆင်ရလွယ်ကူစေရန်
|
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
//append မသုံးရင်စာကြောင်းပိုရှဉ္လို့ append နဲံရေး
|
//社員テーブルから指定された社員IDに一致するデータを取得
|
||||||
sql.append(" SELECT ");
|
sql.append(" SELECT ");
|
||||||
sql.append(" " + ID_EMPLOYEE + ",");
|
sql.append(" " + "*");
|
||||||
sql.append(" " + NM_EMPLOYEE + ",");
|
|
||||||
sql.append(" " + KN_EMPLOYEE + ",");
|
|
||||||
sql.append(" " + MAIL_ADDRESS + ",");
|
|
||||||
sql.append(" " + PASSWORD + ",");
|
|
||||||
sql.append(" " + ID_DEPARTMENT);
|
|
||||||
sql.append(" FROM ");
|
sql.append(" FROM ");
|
||||||
sql.append(" " + TBL_NAME);
|
sql.append(" " + TBL_NAME);
|
||||||
sql.append(" WHERE ");
|
sql.append(" WHERE ");
|
||||||
sql.append(" " + ID_EMPLOYEE + " = ? ");
|
sql.append(" " + ID_EMPLOYEE);
|
||||||
|
sql.append(" = ");
|
||||||
|
sql.append(" " + id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.stmt = con.prepareStatement(sql.toString());
|
this.stmt = con.prepareStatement(sql.toString());
|
||||||
this.stmt.setInt(1, empId);
|
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
|
//DBのカラムをリストに追加
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
EmployeeDTO dto = new EmployeeDTO();
|
EmployeeDTO dto = new EmployeeDTO();
|
||||||
dto.setIdEmployee(rs.getInt(ID_EMPLOYEE));
|
dto.setEmpid(rs.getInt(ID_EMPLOYEE));
|
||||||
dto.setNmEmployee(rs.getString(NM_EMPLOYEE));
|
dto.setName(rs.getString(NM_EMPLOYEE));
|
||||||
dto.setKnEmployee(rs.getString(KN_EMPLOYEE));
|
dto.setKana(rs.getString(KN_EMPLOYEE));
|
||||||
dto.setMailAddress(rs.getString(MAIL_ADDRESS));
|
dto.setMail(rs.getString(MAIL_ADDRESS));
|
||||||
dto.setPassword(rs.getString(PASSWORD));
|
dto.setPass(rs.getString(PASSWORD));
|
||||||
dto.setIdDepartment(rs.getInt(ID_DEPARTMENT));
|
dto.setDepid(rs.getInt(ID_DEPARTMENT));
|
||||||
|
|
||||||
rtnList.add(dto);
|
rtnList.add(dto);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
DbUtil.closeStatement(this.stmt);
|
DbUtil.closeStatement(this.stmt);
|
||||||
}
|
}
|
||||||
|
if (rtnList.size() == 0) {
|
||||||
|
System.out.println("入力された値で情報が見つかりませんでした");
|
||||||
|
}
|
||||||
return rtnList;
|
return rtnList;
|
||||||
|
|
||||||
}
|
}
|
||||||
//Delete method
|
|
||||||
public void empDelete(int empId) throws ClassNotFoundException, SQLException {
|
public void empDelete(int id) throws SQLException {
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
sql.append(" DELETE FROM ");
|
//社員テーブルから指定された社員IDに一致するデータを取得
|
||||||
|
sql.append(" DELETE ");
|
||||||
|
sql.append(" " + "*");
|
||||||
|
sql.append(" FROM ");
|
||||||
sql.append(" " + TBL_NAME);
|
sql.append(" " + TBL_NAME);
|
||||||
sql.append(" WHERE ");
|
sql.append(" WHERE ");
|
||||||
sql.append(" " + ID_EMPLOYEE + " = ? ");
|
sql.append(" " + ID_EMPLOYEE);
|
||||||
//for check
|
sql.append(" = ");
|
||||||
|
sql.append(" " + id);
|
||||||
try {
|
try {
|
||||||
this.stmt = con.prepareStatement(sql.toString());
|
this.stmt = con.prepareStatement(sql.toString());
|
||||||
this.stmt.setInt(1, empId);
|
|
||||||
this.stmt.executeUpdate();
|
this.stmt.executeUpdate();
|
||||||
|
System.out.println("削除が完了しました");
|
||||||
} finally {
|
} finally {
|
||||||
DbUtil.closeStatement(this.stmt);
|
DbUtil.closeStatement(this.stmt);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void empInsert (String nmemp, String knname,String mail, String pw, int deptId) throws ClassNotFoundException, SQLException{
|
}
|
||||||
|
public void emplnsert (String name, String kana, String mail, String pass, int id) {
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
sql.append("INSERT INTO");
|
|
||||||
sql.append(" " + TBL_NAME);
|
|
||||||
sql.append(" ( ");
|
|
||||||
|
|
||||||
sql.append(" " + NM_EMPLOYEE + ",");
|
|
||||||
sql.append(" " + KN_EMPLOYEE + ",");
|
|
||||||
sql.append(" " + MAIL_ADDRESS + ",");
|
|
||||||
sql.append(" " + PASSWORD + ",");
|
|
||||||
sql.append(" " + ID_DEPARTMENT);
|
|
||||||
sql.append(" ) ");
|
|
||||||
sql.append(" VALUES (?, ?, ?, ?, ?) ");
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.stmt = con.prepareStatement(sql.toString());
|
|
||||||
this.stmt.setString(1, nmemp);
|
|
||||||
this.stmt.setString(2, knname);
|
|
||||||
this.stmt.setString(3, mail);
|
|
||||||
this.stmt.setString(4, pw);
|
|
||||||
this.stmt.setInt(5, deptId);
|
|
||||||
|
|
||||||
this.stmt.executeUpdate();
|
|
||||||
} finally {
|
|
||||||
DbUtil.closeStatement(this.stmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public void empUpdate (String nmemp, String knname,String mail, String pw, int deptId,int empId) throws ClassNotFoundException, SQLException{
|
|
||||||
StringBuilder sql = new StringBuilder();
|
|
||||||
sql.append("UPDATE ");
|
|
||||||
sql.append(" " + TBL_NAME);
|
|
||||||
sql.append(" SET ");
|
|
||||||
|
|
||||||
sql.append(" " + NM_EMPLOYEE + " = ?, ");
|
|
||||||
sql.append(" " + KN_EMPLOYEE + " = ?, ");
|
|
||||||
sql.append(" " + MAIL_ADDRESS + " = ?, ");
|
|
||||||
sql.append(" " + PASSWORD + " = ?, ");
|
|
||||||
sql.append(" " + ID_DEPARTMENT + " = ? ");
|
|
||||||
sql.append(" WHERE ");
|
|
||||||
sql.append(" " + ID_EMPLOYEE + " = ? ");
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.stmt = con.prepareStatement(sql.toString());
|
|
||||||
this.stmt.setString(1, nmemp);
|
|
||||||
this.stmt.setString(2, knname);
|
|
||||||
this.stmt.setString(3, mail);
|
|
||||||
this.stmt.setString(4, pw);
|
|
||||||
this.stmt.setInt(5, deptId);
|
|
||||||
this.stmt.setInt(6, empId);
|
|
||||||
|
|
||||||
this.stmt.executeUpdate();
|
|
||||||
} finally {
|
|
||||||
DbUtil.closeStatement(this.stmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,6 +45,8 @@ public class Main {
|
|||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public void start() throws ClassNotFoundException, SQLException {
|
public void start() throws ClassNotFoundException, SQLException {
|
||||||
|
Connection con = DbUtil.getConnection();
|
||||||
|
EmployeeDAO empDao = new EmployeeDAO(con);
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("現在のメンテナンス対象テーブル:" + targetTableName(tblFlg));
|
System.out.println("現在のメンテナンス対象テーブル:" + targetTableName(tblFlg));
|
||||||
System.out.println("1:検索 2:登録 3:更新 4:削除 9:テーブル切替 0:終了");
|
System.out.println("1:検索 2:登録 3:更新 4:削除 9:テーブル切替 0:終了");
|
||||||
@@ -54,10 +56,8 @@ public class Main {
|
|||||||
empSelect();
|
empSelect();
|
||||||
break;
|
break;
|
||||||
case "2":
|
case "2":
|
||||||
empInsert();
|
|
||||||
break;
|
break;
|
||||||
case "3":
|
case "3":
|
||||||
empUpdate();
|
|
||||||
break;
|
break;
|
||||||
case "4":
|
case "4":
|
||||||
empDelete();
|
empDelete();
|
||||||
@@ -73,62 +73,25 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void empUpdate() throws ClassNotFoundException, SQLException{
|
private void empDelete() throws SQLException {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
Connection con = DbUtil.getConnection();
|
Connection con = DbUtil.getConnection();
|
||||||
EmployeeDAO empDao = new EmployeeDAO(con);
|
EmployeeDAO empDao = new EmployeeDAO(con);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// ID ရိုက်ထည့်ခိုင်းခြင်း
|
|
||||||
String strId = inputCheck("ID", true);
|
String strId = inputCheck("ID", true);
|
||||||
int id = Integer.parseInt(strId);
|
int id = Integer.parseInt(strId);
|
||||||
|
List<EmployeeDTO> empList = empDao.selectByld(id);
|
||||||
// ID ရှိမရှိ စစ်ဆေးခြင်း (selectById ကို သုံးပါ)
|
|
||||||
List<EmployeeDTO> empList = empDao.selectById(id);
|
|
||||||
if (empList.isEmpty()) {
|
if (empList.isEmpty()) {
|
||||||
System.out.println("入力された値で情報がみつかりませんでした");
|
} else {
|
||||||
return;
|
System.out.println("指定されたIDの情報を削除します? Y/y");
|
||||||
}
|
System.out.println("Y/y以外の入力であればキャンセル");
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
// အချက်အလက် အသစ်များ တောင်းခံခြင်း
|
String str = sc.nextLine();
|
||||||
String name = inputCheck("社員名", false);
|
if (str.equals("Y") || str.equals("y")) {
|
||||||
String kana = inputCheck("フリガナ", false);
|
empDao.empDelete(id);
|
||||||
String mail = inputCheck("メールアドレス", false);
|
} else {
|
||||||
String pass = inputCheck("パスワード", false);
|
System.out.println("キャンセルしました");
|
||||||
|
|
||||||
String strDeptId = inputCheck("部署ID", true);
|
|
||||||
int deptId = Integer.parseInt(strDeptId);
|
|
||||||
|
|
||||||
// DB ထဲသို့ ပြင်ဆင်ချက် ထည့်သွင်းခြင်း
|
|
||||||
empDao.empUpdate(name, kana, mail, pass, deptId,id);
|
|
||||||
System.out.println("更新が完了しました");
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
DbUtil.closeConnection(empDao.con);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void empInsert() throws ClassNotFoundException, SQLException {
|
|
||||||
Connection con = DbUtil.getConnection();
|
|
||||||
EmployeeDAO empDao = new EmployeeDAO(con);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// အချက်အလက်များ အသီးသီး တောင်းခံခြင်း (inputCheck ကို သုံးပါ)
|
|
||||||
String name = inputCheck("社員名", false);
|
|
||||||
String kana = inputCheck("フリガナ", false);
|
|
||||||
String mail = inputCheck("メールアドレス", false);
|
|
||||||
String pass = inputCheck("パスワード", false);
|
|
||||||
|
|
||||||
// 部署ID အတွက် Numerical Check ဖြစ်သည့် true ထည့်ပါမည်
|
|
||||||
String strDeptId = inputCheck("部署ID", true);
|
|
||||||
int deptId = Integer.parseInt(strDeptId);
|
|
||||||
|
|
||||||
// DB ထဲသို့ ထည့်သွင်းခြင်း
|
|
||||||
empDao.empInsert(name, kana, mail, pass, deptId);
|
|
||||||
System.out.println("登録が完了しました");
|
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
DbUtil.closeConnection(empDao.con);
|
DbUtil.closeConnection(empDao.con);
|
||||||
}
|
}
|
||||||
@@ -141,7 +104,6 @@ public class Main {
|
|||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public static void empSelect() throws ClassNotFoundException, SQLException {
|
public static void empSelect() throws ClassNotFoundException, SQLException {
|
||||||
//List<String> empList = new ArrayList<>();
|
|
||||||
List<EmployeeDTO> empList = new ArrayList<>();
|
List<EmployeeDTO> empList = new ArrayList<>();
|
||||||
Connection con = DbUtil.getConnection();
|
Connection con = DbUtil.getConnection();
|
||||||
EmployeeDAO empDao = new EmployeeDAO(con);
|
EmployeeDAO empDao = new EmployeeDAO(con);
|
||||||
@@ -150,70 +112,25 @@ public class Main {
|
|||||||
try {
|
try {
|
||||||
switch (select) {
|
switch (select) {
|
||||||
case "1":
|
case "1":
|
||||||
//empList = empDao.selectAll();
|
|
||||||
empList = empDao.selectAll();
|
empList = empDao.selectAll();
|
||||||
break;
|
break;
|
||||||
case "2":
|
case "2":
|
||||||
// inputCheck 方法ကို သုံးပြီး ID ရိုက်ခိုင်းပါ (数値 check အတွက် true ထည့်ပါ)
|
System.out.println("IDを入力してください");
|
||||||
String strId = inputCheck("ID", true);
|
int id = sc.nextInt();
|
||||||
int id = Integer.parseInt(strId);
|
empList = empDao.selectByld(id);
|
||||||
empList = empDao.selectById(id);
|
break;
|
||||||
;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ရှာဖွေတွေ့ရှိခြင်း မရှိပါက
|
|
||||||
if (empList.isEmpty()) {
|
|
||||||
System.out.println("入力された値で情報がみつかりませんでした");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (EmployeeDTO emp : empList) {
|
for (EmployeeDTO emp : empList) {
|
||||||
//for (String emp : empList) {
|
System.out.println(emp.getEmpid() + "\t" + emp.getName() + "\t" + emp.getKana() + "\t"
|
||||||
//System.out.println(emp);
|
+ emp.getMail() + "\t" + emp.getPass() + "\t" + emp.getDepid());
|
||||||
System.out.println(emp.getIdEmployee() + "\t" +
|
|
||||||
emp.getNmEmployee() + "\t" +
|
|
||||||
emp.getKnEmployee() + "\t" +
|
|
||||||
emp.getMailAddress() + "\t" +
|
|
||||||
emp.getPassword() + "\t" +
|
|
||||||
emp.getIdDepartment());
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
DbUtil.closeConnection(empDao.con);
|
DbUtil.closeConnection(empDao.con);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void empDelete() throws ClassNotFoundException, SQLException {
|
|
||||||
Connection con = DbUtil.getConnection();
|
|
||||||
EmployeeDAO empDao = new EmployeeDAO(con);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// ID ရိုက်ထည့်ခိုင်းခြင်း (inputCheck ကို သုံးပါ)
|
|
||||||
String strId = inputCheck("ID", true);
|
|
||||||
int id = Integer.parseInt(strId);
|
|
||||||
//System.out.println("IDを入力してください");
|
|
||||||
|
|
||||||
// ID ရှိမရှိ စစ်ဆေးခြင်း (selectById ကို သုံးပါ)
|
|
||||||
List<EmployeeDTO> empList = empDao.selectById(id);
|
|
||||||
if (empList.isEmpty()) {
|
|
||||||
System.out.println("入力された値で情報がみつかりませんでした");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ဖျက်ရန် အတည်ပြုချက် (Confirmation) တောင်းခြင်း
|
|
||||||
System.out.println("指定されたIDの情報を削除します? Y/y");
|
|
||||||
String confirm = sc.nextLine();
|
|
||||||
if ("Y".equalsIgnoreCase(confirm)) {
|
|
||||||
empDao.empDelete(id);
|
|
||||||
System.out.println("削除が完了しました");
|
|
||||||
}
|
|
||||||
}finally {
|
|
||||||
DbUtil.closeConnection(empDao.con);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* フラグを判定し、テーブル名を取得する
|
* フラグを判定し、テーブル名を取得する
|
||||||
*
|
*
|
||||||
@@ -241,7 +158,7 @@ public class Main {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String inputCheck(String titleName, boolean flg) {
|
public static String inputCheck(String titleName, boolean flg) {
|
||||||
String str = null;
|
String str;
|
||||||
while (true) {
|
while (true) {
|
||||||
System.out.println(titleName + "を入力してください");
|
System.out.println(titleName + "を入力してください");
|
||||||
str = sc.nextLine();
|
str = sc.nextLine();
|
||||||
@@ -263,7 +180,4 @@ public class Main {
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,19 +42,14 @@ public class DbUtil {
|
|||||||
* 例外 :ClassNotFoundException, SQLException
|
* 例外 :ClassNotFoundException, SQLException
|
||||||
* 処理 :JDBCドライバを読み込み後、DB接続する。
|
* 処理 :JDBCドライバを読み込み後、DB接続する。
|
||||||
* 生成されたConnectionを返却する
|
* 生成されたConnectionを返却する
|
||||||
* ※Connection生成には上記の定数を活用してくださ
|
* ※Connection生成には上記の定数を活用してください
|
||||||
*/
|
*/
|
||||||
|
public static Connection getConnection() throws SQLException {
|
||||||
public static Connection getConnection() throws ClassNotFoundException, SQLException {
|
//データベースへの接続
|
||||||
//connection is null or not null and create new
|
con = DriverManager.getConnection(DB_URL, DB_USER ,DB_PASS);
|
||||||
if (con == null || con.isClosed()) {
|
|
||||||
Class.forName(DB_DRIVER);
|
|
||||||
con = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
|
|
||||||
}
|
|
||||||
return con;
|
return con;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO 以下の仕様でメソッドを作成してください。
|
* TODO 以下の仕様でメソッドを作成してください。
|
||||||
*
|
*
|
||||||
@@ -64,14 +59,12 @@ public class DbUtil {
|
|||||||
* 例外 :SQLException
|
* 例外 :SQLException
|
||||||
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
|
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
|
||||||
*/
|
*/
|
||||||
public static void closeStatement(PreparedStatement stmt) throws SQLException {
|
public static void closeStatement(PreparedStatement ps) throws SQLException {
|
||||||
if (stmt != null) {
|
//DBステートメントのクローズ
|
||||||
stmt.close();
|
if (ps != null) {
|
||||||
|
ps.close(); //DBステートメントをクローズ
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO 以下の仕様でメソッドを作成してください。
|
* TODO 以下の仕様でメソッドを作成してください。
|
||||||
*
|
*
|
||||||
@@ -82,10 +75,10 @@ public class DbUtil {
|
|||||||
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
|
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
|
||||||
*/
|
*/
|
||||||
public static void closeConnection(Connection con) throws SQLException {
|
public static void closeConnection(Connection con) throws SQLException {
|
||||||
if(con != null) {
|
//コネクションの切断
|
||||||
con.close();
|
if (con != null) {
|
||||||
|
con.close(); //コネクション切断
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user