[Java]データベース(MySQL)の切断のサンプル
関数
void close() throws SQLException
使用例
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){ // 例外処理コード } }