1日目 2段階目まで

This commit is contained in:
2026-10-28 16:58:58 +09:00
parent 9932633268
commit df7972c662
10 changed files with 73 additions and 4 deletions

8
.classpath Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<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"/>
</classpath>

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/bin/

23
.project Normal file
View 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.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

7
.settings/.jsdtscope Normal file
View File

@@ -0,0 +1,7 @@
<?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>

View File

@@ -0,0 +1 @@
org.eclipse.wst.jsdt.launching.JRE_CONTAINER

View File

@@ -0,0 +1 @@
Global

View File

@@ -13,6 +13,7 @@ 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 com.rhizome.example.util.DbUtil; import com.rhizome.example.util.DbUtil;
public class EmployeeDAO { public class EmployeeDAO {
@@ -48,8 +49,8 @@ public class EmployeeDAO {
* @throws SQLException * @throws SQLException
* @throws ClassNotFoundException * @throws ClassNotFoundException
*/ */
public List<String> selectAll() throws SQLException, ClassNotFoundException { public List<EmployeeDTO> selectAll() throws SQLException, ClassNotFoundException {
List<String> rtnList = new ArrayList<>(); List<EmployeeDTO> rtnList = new ArrayList<>();
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.append(" SELECT "); sql.append(" SELECT ");
sql.append(" " + "*"); sql.append(" " + "*");
@@ -63,7 +64,7 @@ public class EmployeeDAO {
rtnList.add(rs.getString(NM_EMPLOYEE)); rtnList.add(rs.getString(NM_EMPLOYEE));
} }
} finally { } finally {
DbUtil.closeStatement(this.stmt); DbUtil.closeStatement​(this.stmt);
} }
return rtnList; return rtnList;
} }

View File

@@ -0,0 +1,7 @@
package com.rhizome.example.dto;
public class EmployeeDTO {
}

View File

@@ -93,7 +93,7 @@ public class Main {
System.out.println(emp); System.out.println(emp);
} }
} finally { } finally {
DbUtil.closeConnection(empDao.con); DbUtil.closeConnection​(empDao.con);
} }
} }

View File

@@ -1,6 +1,7 @@
package com.rhizome.example.util; package com.rhizome.example.util;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager;
public class DbUtil { public class DbUtil {
// 定数定義(共通) // 定数定義(共通)
@@ -42,6 +43,10 @@ public class DbUtil {
* ※Connection生成には上記の定数を活用してください * ※Connection生成には上記の定数を活用してください
*/ */
public static java.sql.Connection getConnection() throws java.lang.ClassNotFoundException, java.sql.SQLException {
con = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
return con;
}
/* /*
* TODO 以下の仕様でメソッドを作成してください。 * TODO 以下の仕様でメソッドを作成してください。
@@ -53,6 +58,11 @@ public class DbUtil {
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする * 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
*/ */
public static void closeStatement​(java.sql.PreparedStatement stmt) throws java.sql.SQLException {
if (stmt != null) {
stmt.close();
}
}
/* /*
* TODO 以下の仕様でメソッドを作成してください。 * TODO 以下の仕様でメソッドを作成してください。
@@ -64,5 +74,15 @@ public class DbUtil {
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する * 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
*/ */
//public static void closeConnection(Connection con) throws SQLException {
//if (con != null) {
//con.close();
//}
//
public static void closeConnection​(java.sql.Connection con) throws java.sql.SQLException {
if (con != null)
con.close();
}
} }