[Java]データベース(MySQL)の切断のサンプル

2021年8月12日

関数
void close() throws SQLException
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Connection conn = null;
String url = "jdbc:mysql://127.0.0.1/sampledb";
String user = "root01";
String password = "67890";
try{
conn = DriverManager.getConnection(url, user, password);
// some code
}catch (SQLException e){
// 例外処理コード
}finally{
try{
if (conn != null){
conn.close();
}
}catch (SQLException e){
// 例外処理コード
}
}
Connection conn = null; String url = "jdbc:mysql://127.0.0.1/sampledb"; String user = "root01"; String password = "67890"; try{ conn = DriverManager.getConnection(url, user, password); // some code }catch (SQLException e){ // 例外処理コード }finally{ try{ if (conn != null){ conn.close(); } }catch (SQLException e){ // 例外処理コード } }
Connection conn = null;
String url = "jdbc:mysql://127.0.0.1/sampledb";
String user = "root01";
String password = "67890";

try{
  conn = DriverManager.getConnection(url, user, password);

  // some code

}catch (SQLException e){
  // 例外処理コード
}finally{
  try{
    if (conn != null){
      conn.close();
    }
  }catch (SQLException e){
    // 例外処理コード
  }
}

 

Java

Posted by arkgame