Advertisement
rasyid03

editdata

May 15th, 2023
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. public void editData(int id, String jenisRuang, float hargaSewa) {
  2. System.out.println("**EDIT DATA**");
  3.  
  4. try {
  5. conn = DriverManager.getConnection(url, user, password);
  6. String query = "UPDATE ruang SET jenis_ruang=?, harga_sewa=? WHERE id_ruang=?";
  7. pst = conn.prepareStatement(query);
  8. pst.setString(1, jenisRuang);
  9. pst.setFloat(2, hargaSewa);
  10. pst.setInt(3, id);
  11. int rowsAffected = pst.executeUpdate();
  12.  
  13. if (rows
  14. if (rowsAffected > 0) {
  15. System.out.println("Data berhasil diubah.");
  16. } else {
  17. System.out.println("Gagal mengubah data.");
  18. }
  19. } catch (SQLException e) {
  20. System.out.println(e.getMessage());
  21. } finally {
  22. try {
  23. if (pst != null) {
  24. pst.close();
  25. }
  26. if (conn != null) {
  27. conn.close();
  28. }
  29. } catch (SQLException e) {
  30. System.out.println(e.getMessage());
  31. }
  32. }
  33. System.out.println("==============================");
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement