Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 897a006918 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/.metadata/
|
||||
11
.project
11
.project
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>em-jdbc</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -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
|
||||
1
src/com/rhizome/example/main/.gitignore
vendored
1
src/com/rhizome/example/main/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/Main.class
|
||||
1
src/com/rhizome/example/util/.gitignore
vendored
1
src/com/rhizome/example/util/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/DbUtil.class
|
||||
@@ -44,10 +44,18 @@ public class DbUtil {
|
||||
* 生成されたConnectionを返却する
|
||||
* ※Connection生成には上記の定数を活用してください
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -59,10 +67,13 @@ public class DbUtil {
|
||||
* 例外 :SQLException
|
||||
* 処理 :引数のDBステートメントがnullでない場合、そのDBステートメントをクローズする
|
||||
*/
|
||||
public static void closeStatement(PreparedStatement stmt) throws SQLException {
|
||||
//nullチェック
|
||||
public static void closeStatement(PreparedStatement stmt) {
|
||||
if (stmt != null) {
|
||||
stmt.close();
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,11 +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) {
|
||||
con.close();
|
||||
|
||||
try {
|
||||
if (!con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user