Compare commits
2 Commits
hirayama
...
fa98c66334
| Author | SHA1 | Date | |
|---|---|---|---|
| fa98c66334 | |||
| 3973a0b1e1 |
@@ -1,8 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
|
<classpathentry kind="src" path=""/>
|
||||||
|
<classpathentry kind="lib" path="mysql-connector-java-8.0.23.jar"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry kind="src" path="src"/>
|
|
||||||
<classpathentry kind="lib" path="lib/mysql-connector-java-8.0.23.jar"/>
|
|
||||||
<classpathentry kind="lib" path="実行例/DAO_Simple.jar"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
|
|
||||||
<classpathentry kind="src" path=""/>
|
|
||||||
<classpathentry kind="output" path=""/>
|
|
||||||
</classpath>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
org.eclipse.wst.jsdt.launching.JRE_CONTAINER
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Global
|
|
||||||
23
bin/.project
Normal file
23
bin/.project
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>em-jdbc</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,2 +0,0 @@
|
|||||||
java -jar DAO_Simple.jar
|
|
||||||
pause
|
|
||||||
BIN
mysql-connector-java-8.0.23.jar
Normal file
BIN
mysql-connector-java-8.0.23.jar
Normal file
Binary file not shown.
8
snippet/Snippet.java
Normal file
8
snippet/Snippet.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package snippet;
|
||||||
|
|
||||||
|
public class Snippet {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,10 +1,4 @@
|
|||||||
/*
|
package src.com.rhizome.example.dao;
|
||||||
* EmployeeDAO.java
|
|
||||||
* 作成 IT-College 2020
|
|
||||||
*------------------------------------------------------------
|
|
||||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
|
||||||
*/
|
|
||||||
package com.rhizome.example.dao;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@@ -13,8 +7,8 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.rhizome.example.dto.EmployeeDTO;
|
import src.com.rhizome.example.dto.EmployeeDTO;
|
||||||
import com.rhizome.example.util.DbUtil;
|
import src.com.rhizome.example.util.DbUtil;
|
||||||
|
|
||||||
public class EmployeeDAO {
|
public class EmployeeDAO {
|
||||||
private static final String TBL_NAME = "employee";
|
private static final String TBL_NAME = "employee";
|
||||||
@@ -27,7 +21,7 @@ public class EmployeeDAO {
|
|||||||
|
|
||||||
/** DBコネクション */
|
/** DBコネクション */
|
||||||
public Connection con;
|
public Connection con;
|
||||||
/** DBステートPreparedStatement stmtメント */
|
/** DBステートメント */
|
||||||
PreparedStatement stmt;
|
PreparedStatement stmt;
|
||||||
/** 検索結果 */
|
/** 検索結果 */
|
||||||
ResultSet rs;
|
ResultSet rs;
|
||||||
@@ -61,25 +55,129 @@ public class EmployeeDAO {
|
|||||||
this.stmt = con.prepareStatement(sql.toString());
|
this.stmt = con.prepareStatement(sql.toString());
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
EmployeeDTO dto =
|
||||||
//インスタンス生成
|
new EmployeeDTO();
|
||||||
EmployeeDTO emp = new EmployeeDTO();
|
|
||||||
|
dto.setIdEmployee(
|
||||||
emp.setId(rs.getInt("id_employee"));
|
rs.getInt("ID_EMPLOYEE"));
|
||||||
emp.setName(rs.getString("nm_employee"));
|
|
||||||
emp.setKana(rs.getString("kn_employee"));
|
dto.setNmEmployee(
|
||||||
emp.setEmail(rs.getString("mail_address"));
|
rs.getString("NM_EMPLOYEE"));
|
||||||
emp.setPass(rs.getString("password"));
|
|
||||||
emp.setIdDep(rs.getInt("id_department"));
|
dto.setKnEmployee(
|
||||||
|
rs.getString("KN_EMPLOYEE"));
|
||||||
rtnList.add(emp);
|
|
||||||
|
dto.setMailEmployee(
|
||||||
|
rs.getString("MAIL_ADDRESS"));
|
||||||
|
|
||||||
|
dto.setPassEmployee(
|
||||||
|
rs.getString("PASSWORD"));
|
||||||
|
|
||||||
|
dto.setIdDepartment(
|
||||||
|
rs.getInt("ID_DEPARTMENT"));
|
||||||
|
|
||||||
|
rtnList.add(dto);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
DbUtil.closeStatement(this.stmt);
|
DbUtil.closeStatement(this.stmt);
|
||||||
}
|
}
|
||||||
return rtnList;
|
return rtnList;
|
||||||
}
|
}
|
||||||
|
public List<EmployeeDTO> selectById(int employeeId) throws SQLException{
|
||||||
|
List<EmployeeDTO>rtnList = new ArrayList<>();
|
||||||
|
|
||||||
|
java.lang.String sql =
|
||||||
|
"SELECT * FROM employee WHERE id_employee = ?";
|
||||||
|
try {
|
||||||
|
stmt = con.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, employeeId);
|
||||||
|
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
|
||||||
|
EmployeeDTO dto = new EmployeeDTO();
|
||||||
|
|
||||||
|
dto.setIdEmployee(rs.getInt(ID_EMPLOYEE));
|
||||||
|
dto.setNmEmployee(rs.getString(NM_EMPLOYEE));
|
||||||
|
dto.setKnEmployee(rs.getString(KN_EMPLOYEE));
|
||||||
|
dto.setMailEmployee(rs.getString(MAIL_ADDRESS));
|
||||||
|
dto.setPassEmployee(rs.getString(PASSWORD));
|
||||||
|
dto.setIdDepartment(rs.getInt(ID_DEPARTMENT));
|
||||||
|
|
||||||
|
rtnList.add(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
DbUtil.closeStatement(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rtnList;
|
||||||
|
}
|
||||||
|
public int empDelete (int employeeId)throws SQLException{
|
||||||
|
java.lang.String sql =
|
||||||
|
"DELETE FROM employee WHERE id_employee = ?";
|
||||||
|
try {
|
||||||
|
stmt = con.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, employeeId);
|
||||||
|
|
||||||
|
return stmt.executeUpdate();
|
||||||
|
} finally {
|
||||||
|
DbUtil.closeStatement(stmt);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int empInsert(String employeeName,String employeeKn,String employeeMail
|
||||||
|
,String employeePass, int departmentId)throws SQLException{
|
||||||
|
java.lang.String sql =
|
||||||
|
"INSERT INTO employee " +
|
||||||
|
"(nm_employee, kn_employee, mail_address, password, id_department) " +
|
||||||
|
"VALUES (?, ?, ?, ?, ?)";
|
||||||
|
try {
|
||||||
|
stmt = con.prepareStatement(sql);
|
||||||
|
stmt.setString(1, employeeName);
|
||||||
|
stmt.setString(2, employeeKn);
|
||||||
|
stmt.setString(3, employeeMail);
|
||||||
|
stmt.setString(4, employeePass);
|
||||||
|
stmt.setInt(5, departmentId);
|
||||||
|
|
||||||
|
return stmt.executeUpdate();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
DbUtil.closeStatement(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int empUpdate(int employeeId,String employeeName,String employeeKn,String employeeMail
|
||||||
|
,String employeePass, int departmentId)throws SQLException{
|
||||||
|
java.lang.String sql =
|
||||||
|
"UPDATE employee " +
|
||||||
|
"SET nm_employee = ?, " +
|
||||||
|
"kn_employee = ?, " +
|
||||||
|
"mail_address = ?, " +
|
||||||
|
"password = ?, " +
|
||||||
|
"id_department = ? " +
|
||||||
|
"WHERE id_employee = ?";
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
stmt = con.prepareStatement(sql);
|
||||||
|
|
||||||
|
stmt.setString(1, employeeName);
|
||||||
|
stmt.setString(2, employeeKn);
|
||||||
|
stmt.setString(3, employeeMail);
|
||||||
|
stmt.setString(4, employeePass);
|
||||||
|
stmt.setInt(5, departmentId);
|
||||||
|
stmt.setInt(6, employeeId);
|
||||||
|
|
||||||
|
return stmt.executeUpdate();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
DbUtil.closeStatement(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +1,51 @@
|
|||||||
package com.rhizome.example.dto;
|
package src.com.rhizome.example.dto;
|
||||||
|
|
||||||
//フィールド
|
|
||||||
public class EmployeeDTO {
|
public class EmployeeDTO {
|
||||||
private Integer id;
|
private int idEmployee;
|
||||||
private String name;
|
private String nmEmployee;
|
||||||
private String kana;
|
private String knEmployee;
|
||||||
private String email;
|
private String mailEmployee;
|
||||||
private String pass;
|
private String passEmployee;
|
||||||
private Integer idDep;
|
private int idDepartment;
|
||||||
|
|
||||||
//ゲッター・セッター
|
|
||||||
public Integer getId() {
|
public int getIdEmployee() {
|
||||||
return id;
|
return idEmployee;
|
||||||
}
|
}
|
||||||
public String getName() {
|
public void setIdEmployee(int idEmployee) {
|
||||||
return name;
|
this.idEmployee = idEmployee;
|
||||||
}
|
}
|
||||||
public String getKana() {
|
public String getNmEmployee() {
|
||||||
return kana;
|
return nmEmployee;
|
||||||
}
|
}
|
||||||
public String getEmail() {
|
public void setNmEmployee(String nmEmployee) {
|
||||||
return email;
|
this.nmEmployee = nmEmployee;
|
||||||
}
|
}
|
||||||
public String getPass() {
|
public String getKnEmployee() {
|
||||||
return pass;
|
return knEmployee;
|
||||||
}
|
}
|
||||||
public Integer getIdDep() {
|
public void setKnEmployee(String knEmployee) {
|
||||||
return idDep;
|
this.knEmployee = knEmployee;
|
||||||
}
|
}
|
||||||
public void setId(Integer id) {
|
public String getMailEmployee() {
|
||||||
this.id = id;
|
return mailEmployee;
|
||||||
}
|
}
|
||||||
public void setName(String name) {
|
public void setMailEmployee(String mailEmployee) {
|
||||||
this.name = name;
|
this.mailEmployee = mailEmployee;
|
||||||
}
|
}
|
||||||
public void setKana(String kana) {
|
public String getPassEmployee() {
|
||||||
this.kana = kana;
|
return passEmployee;
|
||||||
}
|
}
|
||||||
public void setEmail(String email) {
|
public void setPassEmployee(String passEmployee) {
|
||||||
this.email = email;
|
this.passEmployee = passEmployee;
|
||||||
}
|
}
|
||||||
public void setPass(String pass) {
|
public int getIdDepartment() {
|
||||||
this.pass = pass;
|
return idDepartment;
|
||||||
}
|
}
|
||||||
public void setIdDep(Integer idDep) {
|
public void setIdDepartment(int idDepartment) {
|
||||||
this.idDep = idDep;
|
this.idDepartment = idDepartment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.rhizome.example.main;
|
package src.com.rhizome.example.main;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@@ -6,9 +6,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import com.rhizome.example.dao.EmployeeDAO;
|
import src.com.rhizome.example.dao.EmployeeDAO;
|
||||||
import com.rhizome.example.dto.EmployeeDTO;
|
import src.com.rhizome.example.dto.EmployeeDTO;
|
||||||
import com.rhizome.example.util.DbUtil;
|
import src.com.rhizome.example.util.DbUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author IT-College
|
* @author IT-College
|
||||||
@@ -54,10 +54,13 @@ 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();
|
||||||
break;
|
break;
|
||||||
case "9":
|
case "9":
|
||||||
return;
|
return;
|
||||||
@@ -87,15 +90,35 @@ public class Main {
|
|||||||
case "1":
|
case "1":
|
||||||
empList = empDao.selectAll();
|
empList = empDao.selectAll();
|
||||||
break;
|
break;
|
||||||
|
case "2":
|
||||||
|
|
||||||
|
String strId = inputCheck("ID", true);
|
||||||
|
int id = Integer.parseInt(strId);
|
||||||
|
empList = empDao.selectById(id);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (EmployeeDTO emp : empList) {
|
if(empList.isEmpty()){
|
||||||
System.out.println(emp);
|
System.out.println("入力された値で情報がみつかりませんでした");
|
||||||
|
}else {
|
||||||
|
|
||||||
|
for (EmployeeDTO emp : empList) {
|
||||||
|
System.out.println(
|
||||||
|
emp.getIdEmployee() + "\t"
|
||||||
|
+ emp.getNmEmployee() + "\t"
|
||||||
|
+ emp.getKnEmployee() + "\t"
|
||||||
|
+ emp.getMailEmployee() + "\t"
|
||||||
|
+ emp.getPassEmployee() + "\t"
|
||||||
|
+ emp.getIdDepartment() + "\t");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
}finally {
|
||||||
DbUtil.closeConnection(empDao.con);
|
DbUtil.closeConnection(empDao.con);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,4 +170,100 @@ public class Main {
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
public static void empDelete() throws ClassNotFoundException, SQLException {
|
||||||
|
|
||||||
|
Connection con = DbUtil.getConnection();
|
||||||
|
EmployeeDAO empDao = new EmployeeDAO(con);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
String strId = inputCheck("ID", true);
|
||||||
|
int id = Integer.parseInt(strId);
|
||||||
|
|
||||||
|
int count = empDao.empDelete(id);
|
||||||
|
|
||||||
|
if (count == 0) {
|
||||||
|
System.out.println("入力されたIDの情報は見つかりませんでした。");
|
||||||
|
} else {
|
||||||
|
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 {
|
||||||
|
|
||||||
|
String name= inputCheck("社員名", false);
|
||||||
|
String kana = inputCheck("フリガナ", false);
|
||||||
|
String mail = inputCheck("メールアドレス", false);
|
||||||
|
String pass = inputCheck("パスワード", false);
|
||||||
|
|
||||||
|
int depId = Integer.parseInt(inputCheck("部署ID", true));
|
||||||
|
|
||||||
|
int count = empDao.empInsert(
|
||||||
|
name,
|
||||||
|
kana,
|
||||||
|
mail,
|
||||||
|
pass,
|
||||||
|
depId);
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
System.out.println("登録が完了しました");
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
DbUtil.closeConnection(empDao.con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void empUpdate() throws ClassNotFoundException, SQLException {
|
||||||
|
|
||||||
|
Connection con = DbUtil.getConnection();
|
||||||
|
EmployeeDAO empDao = new EmployeeDAO(con);
|
||||||
|
String strId = inputCheck("ID", true);
|
||||||
|
|
||||||
|
int id = Integer.parseInt(strId);
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
String name =
|
||||||
|
inputCheck("社員名", false);
|
||||||
|
|
||||||
|
String kana =
|
||||||
|
inputCheck("フリガナ", false);
|
||||||
|
|
||||||
|
String mail =
|
||||||
|
inputCheck("メールアドレス", false);
|
||||||
|
|
||||||
|
String pass =
|
||||||
|
inputCheck("パスワード", false);
|
||||||
|
|
||||||
|
int depId =
|
||||||
|
Integer.parseInt(inputCheck("部署ID", true));
|
||||||
|
|
||||||
|
|
||||||
|
int count = empDao.empUpdate(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
kana,
|
||||||
|
mail,
|
||||||
|
pass,
|
||||||
|
depId);
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
System.out.println("更新が完了しました");
|
||||||
|
} else {
|
||||||
|
System.out.println("入力されたIDの情報は見つかりませんでした。");
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
DbUtil.closeConnection(empDao.con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.rhizome.example.util;
|
package src.com.rhizome.example.util;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
@@ -44,23 +44,23 @@ public class DbUtil {
|
|||||||
* 生成されたConnectionを返却する
|
* 生成されたConnectionを返却する
|
||||||
* ※Connection生成には上記の定数を活用してください
|
* ※Connection生成には上記の定数を活用してください
|
||||||
*/
|
*/
|
||||||
public static Connection getConnection() {
|
public static Connection getConnection()
|
||||||
try {
|
throws ClassNotFoundException, SQLException{
|
||||||
|
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
if(con != null && !con.isClosed()) {
|
||||||
|
return con;
|
||||||
|
}
|
||||||
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
|
con = DriverManager.getConnection(
|
||||||
|
DB_URL,
|
||||||
|
DB_USER,
|
||||||
|
DB_PASS);
|
||||||
|
|
||||||
|
return con;
|
||||||
|
|
||||||
con = DriverManager.getConnection(
|
|
||||||
"jdbc:mysql://127.0.0.1:3306/rezodb" // データベース
|
|
||||||
, "rezouser" // ユーザ
|
|
||||||
, "Rezo_0000" // パスワード
|
|
||||||
);
|
|
||||||
}catch (ClassNotFoundException e){
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return con;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -72,15 +72,12 @@ public class DbUtil {
|
|||||||
* 例外 :SQLException
|
* 例外 :SQLException
|
||||||
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
|
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
|
||||||
*/
|
*/
|
||||||
|
public static void closeStatement(
|
||||||
public static void closeStatement(PreparedStatement stmt){
|
PreparedStatement stmt) throws SQLException{
|
||||||
try {
|
if(stmt !=null)
|
||||||
if (stmt != null) stmt.close();
|
stmt.close();
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO 以下の仕様でメソッドを作成してください。
|
* TODO 以下の仕様でメソッドを作成してください。
|
||||||
@@ -91,12 +88,9 @@ public class DbUtil {
|
|||||||
* 例外 :SQLException
|
* 例外 :SQLException
|
||||||
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
|
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
|
||||||
*/
|
*/
|
||||||
public static void closeConnection(Connection con) {
|
public static void closeConnection(Connection con)
|
||||||
try {
|
throws SQLException{
|
||||||
if (con != null) con.close();
|
if(con != null)
|
||||||
} catch (SQLException e) {
|
con.close();
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user