Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. public boolean acceptReturn(String ISBN)
  2.     {
  3.         try
  4.         {
  5.             Statement statementTitleISBN = connection.createStatement();
  6.             ResultSet isbnFromTitles = statementTitleISBN.executeQuery("SELECT ISBN FROM Titles");
  7.            
  8.             Statement statementISBN = connection.createStatement();
  9.             ResultSet isbnFromCheckedOut = statementISBN.executeQuery("SELECT ISBN FROM Checkedout");
  10.            
  11.             ArrayList<String> isbnFromTitlesArrayList = new ArrayList<String>();
  12.             ArrayList<String> isbnFromCheckedOutArrayList = new ArrayList<String>();
  13.            
  14.             while(isbnFromTitles.next())
  15.             {
  16.                 isbnFromTitlesArrayList.add(isbnFromTitles.getString("ISBN").toLowerCase().trim());
  17.             }
  18.            
  19.             while(isbnFromCheckedOut.next())
  20.             {
  21.                 isbnFromCheckedOutArrayList.add(isbnFromCheckedOut.getString("ISBN").toLowerCase().trim());
  22.             }
  23.              if (isbnFromCheckedOutArrayList.contains(ISBN.toLowerCase().trim()))
  24.             {
  25.                 preparedStatement = connection.prepareStatement("DELETE FROM CheckedOut WHERE ISBN = ?");
  26.                 preparedStatement.setString(1, ISBN);
  27.                 preparedStatement.executeUpdate();
  28.                 setQuery("SELECT * FROM CheckedOut");
  29.                 return true;
  30.             }
  31.              else if (!isbnFromCheckedOutArrayList.contains(ISBN.toLowerCase().trim()))
  32.              {
  33.                  JOptionPane.showMessageDialog(null, "Book has already been returned", "Error", JOptionPane.ERROR_MESSAGE);
  34.                  return false;
  35.              }
  36.              else if (!isbnFromTitlesArrayList.contains(ISBN.toLowerCase().trim()))
  37.              {
  38.                  JOptionPane.showMessageDialog(null, "Book not found", "Error", JOptionPane.ERROR_MESSAGE);
  39.                  return false;
  40.              }
  41.              return false;
  42.         } catch (SQLException sqlException)
  43.         {
  44.             sqlException.printStackTrace();
  45.             close();
  46.             return false;
  47.         }
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement