Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. try (Connection connection = **strong text**DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "password")) {
  2.  
  3. try (PreparedStatement stmt = connection.prepareStatement("DELETE * FROM PUBLISHER1 WHERE ID=1")) {
  4. stmt.executeUpdate();
  5. }
  6. // stmt is auto closed here, even if SQLException is thrown
  7.  
  8. try (PreparedStatement stmt = connection.prepareStatement("DELETE *FROM PUBLISHER2 WHERE ID=2");
  9. stmt.executeUpdate();
  10. }
  11. // stmt is auto closed here, even if SQLException is thrown
  12. }
  13. // connection is auto closed here, even if SQLException is thrown
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement