Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1.     public void removeFriend(String friendName) throws SQLException {
  2.         for (int i = 0; i < 24; i++) {
  3.             if (friends[i] != null && friends[i].equals(friendName)) {
  4.                 friends[i] = null;
  5.                
  6.                 Connection con = DatabaseConnection.getConnection();
  7.                 PreparedStatement ps = con.prepareStatement("DELETE FROM friends WHERE username = ? AND friend = ?");
  8.                 ps.setString(1, username);
  9.                 ps.setString(2, friendName);
  10.                 ps.executeUpdate();
  11.                
  12.                 ps.close();
  13.                 con.close();
  14.                 return;
  15.             }
  16.         }
  17.     }
  18.  
  19.  
  20.     public void removeFriend(String friendName) {
  21.         for (Friend friend : friends) {
  22.             if (friend.getFriendName().equals(friendName)) {
  23.                 Session session = DatabaseConnection.getSession();
  24.                 session.beginTransaction();
  25.                 session.delete(friend);
  26.                 session.getTransaction().commit();
  27.                 session.close();
  28.                
  29.                 friends.remove(friend);
  30.             }
  31.         }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement