title: java.sql - ResultSet r.next() doesn't work
body: <p>I don't understand why ResultSet isn't working as if there are no results</p>
  
  <pre><code>public static int checkProductID(Connection conn) {
  
      boolean productIDisvalid = false;
      int id = 0;
      while (!productIDisvalid) {
          System.out.println("Enter a product ID: ");
          try {
              id = Integer.parseInt(readLine());
              if (id &lt; 10000000 &amp;&amp; id &gt; 0) {
                  System.out.println(id);
                  // PreparedStatement pstmt = conn.prepareStatement ("INSERT INTO INVENTORY VALUES (?,?,?,?) ");
                  // pstmt.setInt(1,4000); pstmt.setString(2,"hello"); pstmt.setInt(3,4000); pstmt.setInt(4,400);
                  PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM INVENTORY WHERE PRODUCTID = ?");
                  pstmt.setInt(1, id);
                  ResultSet r = pstmt.executeQuery();
                  while (r.next()) {
                      System.out.println(r.getInt("PRODUCTID"));
                      if (r.getInt("PRODUCTID") == id) return id;
                  }
              }
  
          } catch (NumberFormatException | SQLException | NullPointerException e) {
              e.printStackTrace();
              continue;
          }
      }
  
      return id;
  }
  </code></pre>
  
  <p>I quoted out an insert values to prove it works and that it is correctly connected to the database.</p>
  
  <p><a href="https://i.stack.imgur.com/3SVk3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3SVk3.png" alt="enter image description here"></a></p>
  
  <p>The insert values works. But whenever I attempt to perform a search query on the database, it doesn't work, r.next() is never true and the print statement inside that while loop never executes, even if I change the query to "SELECT * FROM INVENTORY WHERE PRODUCTID = 1000"</p>