「Java」try-with-resources文を使うサンプル

サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
String strSQL ="INSERT INTO TEST_TBL xxxx";
try (PreparedStatement ps = conn.preparedStatement(strSQL)) {
// some code
ret =ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
String strSQL ="INSERT INTO TEST_TBL xxxx"; try (PreparedStatement ps = conn.preparedStatement(strSQL)) { // some code ret =ps.executeUpdate(); } catch (Exception e) { e.printStackTrace(); throw e; }
String strSQL ="INSERT INTO TEST_TBL xxxx";
try (PreparedStatement ps = conn.preparedStatement(strSQL)) {
  // some code
  ret =ps.executeUpdate();
} catch (Exception e) {
   e.printStackTrace();
   throw e;
}

 

Java

Posted by arkgame