Compare commits
1 Commits
m-endo
...
a-takayama
| Author | SHA1 | Date | |
|---|---|---|---|
| 9650f00f45 |
8
.classpath
Normal file
8
.classpath
Normal 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>
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
|||||||
/.metadata/
|
/bin/
|
||||||
|
|||||||
12
.project
12
.project
@@ -5,7 +5,19 @@
|
|||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
<buildSpec>
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
|
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
7
.settings/.jsdtscope
Normal file
7
.settings/.jsdtscope
Normal 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>
|
||||||
1
.settings/org.eclipse.wst.jsdt.ui.superType.container
Normal file
1
.settings/org.eclipse.wst.jsdt.ui.superType.container
Normal file
@@ -0,0 +1 @@
|
|||||||
|
org.eclipse.wst.jsdt.launching.JRE_CONTAINER
|
||||||
1
.settings/org.eclipse.wst.jsdt.ui.superType.name
Normal file
1
.settings/org.eclipse.wst.jsdt.ui.superType.name
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Global
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
|
||||||
<classpathentry kind="src" path=""/>
|
|
||||||
<classpathentry kind="output" path=""/>
|
|
||||||
</classpath>
|
|
||||||
17
src/.project
17
src/.project
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>src</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
||||||
1
src/com/rhizome/example/dao/.gitignore
vendored
1
src/com/rhizome/example/dao/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/EmployeeDAO.class
|
|
||||||
@@ -56,10 +56,11 @@ public class EmployeeDAO {
|
|||||||
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();
|
||||||
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 {
|
||||||
|
|||||||
1
src/com/rhizome/example/main/.gitignore
vendored
1
src/com/rhizome/example/main/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/Main.class
|
|
||||||
@@ -15,6 +15,7 @@ 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テーブル
|
||||||
*/
|
*/
|
||||||
@@ -69,6 +70,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 社員テーブルから情報を検索する
|
* 社員テーブルから情報を検索する
|
||||||
*
|
*
|
||||||
@@ -89,11 +91,14 @@ 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);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
DbUtil.closeConnection(empDao.con);
|
DbUtil.closeConnection(empDao.con);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
src/com/rhizome/example/util/.gitignore
vendored
1
src/com/rhizome/example/util/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/DbUtil.class
|
|
||||||
@@ -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 = "rezouser";
|
private static final String DB_USER = "rezouser1";
|
||||||
private static final String DB_PASS = "Rezo_0000";
|
private static final String DB_PASS = "Rezo_0001";
|
||||||
|
|
||||||
// 定数定義(PostgreSQL用)
|
// 定数定義(PostgreSQL用)
|
||||||
// private static final String DBMS = "postgresql";
|
// private static final String DBMS = "postgresql";
|
||||||
@@ -44,11 +44,22 @@ 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 以下の仕様でメソッドを作成してください。
|
||||||
@@ -59,13 +70,14 @@ public class DbUtil {
|
|||||||
* 例外 :SQLException
|
* 例外 :SQLException
|
||||||
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
|
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
|
||||||
*/
|
*/
|
||||||
public static void closeStatement(PreparedStatement stmt) throws SQLException {
|
// PreparedStatement型 / DBステートメント 例外: SQLException
|
||||||
//nullチェック
|
public static void closeStatement( PreparedStatement stmt) throws SQLException {
|
||||||
if (stmt != null) {
|
//引数のDBステートメントがnullでない場合
|
||||||
|
if(stmt != null) {
|
||||||
|
//そのDBステートメントをクローズする
|
||||||
stmt.close();
|
stmt.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO 以下の仕様でメソッドを作成してください。
|
* TODO 以下の仕様でメソッドを作成してください。
|
||||||
*
|
*
|
||||||
@@ -76,10 +88,11 @@ public class DbUtil {
|
|||||||
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
|
* 処理 :引数のコネクションがnullでない場合、そのコネクションを切断する
|
||||||
*/
|
*/
|
||||||
public static void closeConnection(Connection con) throws SQLException {
|
public static void closeConnection(Connection con) throws SQLException {
|
||||||
//nullチェック
|
//引数のコネクションがnullでない場合
|
||||||
if (con != null) {
|
if(con != null) {
|
||||||
|
//そのコネクションを切断する
|
||||||
con.close();
|
con.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user