1 Commits

Author SHA1 Message Date
897a006918 1段階目です。 2026-09-29 17:21:43 +09:00
9 changed files with 33 additions and 77 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());
rs = stmt.executeQuery();
while (rs.next()) {
// EmployeeDAO dao = new EmployeeDAO(con);
rtnList.add(rs.getString(NM_EMPLOYEE));
}
} finally {

View File

@@ -15,7 +15,6 @@ import com.rhizome.example.util.DbUtil;
*/
public class Main {
static Scanner sc = new Scanner(System.in);
/**
* テーブル切り替え用変数 0:Employeeテーブル 1:Departmentテーブル
*/
@@ -70,7 +69,6 @@ public class Main {
}
}
/**
* 社員テーブルから情報を検索する
*
@@ -91,9 +89,6 @@ public class Main {
default:
return;
}
System.out.println("取得件数" + empList.size());
for (String emp : empList) {
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_NAME = "rezodb";
private static final String DB_USER = "rezouser1";
private static final String DB_PASS = "Rezo_0001";
private static final String DB_USER = "rezouser";
private static final String DB_PASS = "Rezo_0000";
// 定数定義(PostgreSQL用)
// private static final String DBMS = "postgresql";
@@ -44,22 +44,19 @@ public class DbUtil {
* 生成されたConnectionを返却する
* ※Connection生成には上記の定数を活用してください
*/
//例外が2個あるためカンマでつなげることができる
public static Connection getConnection() throws SQLException {
//データベースへの接続
con = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
return con;
public static Connection getConnection() throws ClassNotFoundException, SQLException {
try {
Class.forName(DB_DRIVER);
return DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
} catch (ClassNotFoundException e) {
System.out.println();
throw e;
} catch (SQLException e) {
System.out.println();
throw e;
}
// 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 以下の仕様でメソッドを作成してください。
@@ -70,14 +67,16 @@ public class DbUtil {
* 例外 :SQLException
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
*/
// PreparedStatement型 / DBステートメント 例外: SQLException
public static void closeStatement( PreparedStatement stmt) throws SQLException {
//引数のDBステートメントがnullでない場合
public static void closeStatement(PreparedStatement stmt) {
if (stmt != null) {
//そのDBステートメントをクローズする
try {
stmt.close();
} catch (SQLException e) {
System.out.println();
}
}
}
/*
* TODO 以下の仕様でメソッドを作成してください。
*
@@ -87,12 +86,16 @@ public class DbUtil {
* 例外 :SQLException
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
*/
public static void closeConnection(Connection con) throws SQLException {
//引数のコネクションがnullでない場合
public static void closeConnection(Connection con) {
if (con != null) {
//そのコネクションを切断する
try {
if (!con.isClosed()) {
con.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}