1 Commits

Author SHA1 Message Date
s-ohasi
830d04aed6 1段階目(DB接続処理作成→全検索完成)完了しました。 2026-09-30 11:30:10 +09:00
9 changed files with 17 additions and 78 deletions

View File

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

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

View File

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

View File

@@ -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>

View File

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

View File

@@ -1 +0,0 @@
Global

View File

@@ -60,7 +60,6 @@ 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()) {
// EmployeeDAO dao = new EmployeeDAO(con);
rtnList.add(rs.getString(NM_EMPLOYEE)); rtnList.add(rs.getString(NM_EMPLOYEE));
} }
} finally { } finally {

View File

@@ -15,7 +15,6 @@ import com.rhizome.example.util.DbUtil;
*/ */
public class Main { public class Main {
static Scanner sc = new Scanner(System.in); static Scanner sc = new Scanner(System.in);
/** /**
* テーブル切り替え用変数 0:Employeeテーブル 1:Departmentテーブル * テーブル切り替え用変数 0:Employeeテーブル 1:Departmentテーブル
*/ */
@@ -70,7 +69,6 @@ public class Main {
} }
} }
/** /**
* 社員テーブルから情報を検索する * 社員テーブルから情報を検索する
* *
@@ -91,9 +89,6 @@ public class Main {
default: default:
return; return;
} }
System.out.println("取得件数" + empList.size());
for (String emp : empList) { for (String emp : empList) {
System.out.println(emp); System.out.println(emp);
} }

View File

@@ -9,8 +9,8 @@ public class DbUtil {
// 定数定義(共通) // 定数定義(共通)
private static final String DB_HOST = "127.0.0.1"; private static final String DB_HOST = "127.0.0.1";
private static final String DB_NAME = "rezodb"; private static final String DB_NAME = "rezodb";
private static final String DB_USER = "rezouser1"; private static final String DB_USER = "rezouser";
private static final String DB_PASS = "Rezo_0001"; private static final String DB_PASS = "Rezo_0000";
// 定数定義(PostgreSQL用) // 定数定義(PostgreSQL用)
// private static final String DBMS = "postgresql"; // private static final String DBMS = "postgresql";
@@ -35,7 +35,7 @@ public class DbUtil {
/* /*
* TODO 以下の仕様でメソッドを作成してください。 * TODO 以下の仕様でメソッドを作成してください。
* *1,2をやる
* 戻り値 :Connection * 戻り値 :Connection
* メソッド名 :getConnection * メソッド名 :getConnection
* 引数 :なし * 引数 :なし
@@ -44,55 +44,41 @@ public class DbUtil {
* 生成されたConnectionを返却する * 生成されたConnectionを返却する
* ※Connection生成には上記の定数を活用してください * ※Connection生成には上記の定数を活用してください
*/ */
//例外が2個あるためカンマでつなげることができる
public static Connection getConnection() throws SQLException { public static Connection getConnection() throws SQLException {
//データベースへの接続 //データベースへの接続
con = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS); con = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
return con; return con;
} }
// try {
// Class.forName("com.mysql.cj.jdbc.Driver");
// } catch (ClassNotFoundException e) {
// throw new SQLException("JDBCドライバが見つかりません", e);
// }
// //JDBCドライバの読み込み
// return DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/rezodb"
// , "rezouser1"
// , "Rezo_0001");
/* /*
* TODO 以下の仕様でメソッドを作成してください。 * TODO 以下の仕様でメソッドを作成してください。
* *6をやる
* 戻り値 :なし * 戻り値 :なし
* メソッド名 :closeStatement * メソッド名 :closeStatement
* 引数 :DBステートメント(PreparedStatement型) * 引数 :DBステートメント(PreparedStatement型)
* 例外 :SQLException * 例外 :SQLException
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする * 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
*/ */
// PreparedStatement型 / DBステートメント 例外: SQLException public static void closeStatement(PreparedStatement ps) throws SQLException {
public static void closeStatement( PreparedStatement stmt) throws SQLException { if (ps != null) {
//引数のDBステートメントがnullでない場合 ps.close();
if(stmt != null) {
//そのDBステートメントをクローズする
stmt.close();
} }
} }
/* /*
* TODO 以下の仕様でメソッドを作成してください。 * TODO 以下の仕様でメソッドを作成してください。
* *7
* 戻り値 :なし * 戻り値 :なし
* メソッド名 :closeConnection() * メソッド名 :closeConnection()
* 引数 :切断するコネクション(Connection型) * 引数 :切断するコネクション(Connection型)
* 例外 :SQLException * 例外 :SQLException
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する * 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
*/ */
public static void closeConnection(Connection con) throws SQLException { public static void closeConnection(Connection co) throws SQLException {
//引数のコネクションがnullでない場合 if (co != null) {
if(con != null) { co.close();
//そのコネクションを切断する
con.close();
} }
}
}
} }