title: JDBC.SQLServerException: The result set has no current row
body: <p>So, a solution I created threw this exception: <code>jdbc.SQLServerException: The result set has no current row</code> on the line marked in the below code.</p>
  
  <pre><code>public String get64BitEncodedImageBySiteID(int siteID){
      try {           
          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
          Connection conn = DriverManager.getConnection(url, userName, password);
  
          Statement stmt = conn.createStatement();
          ResultSet rs = stmt.executeQuery( "SELECT SitePicture FROM SiteTable WHERE SiteID ="+siteID );
  
          rs.next();
          // The above line has since been moved to the if statement below where you can see it commented out,
          // which prevents the exception from occuring but still doesn't fix the fact that the row is not being found. 
  
          if(/*rs.next() &amp;&amp;*/ rs.getBytes("SitePicture")!=null){ // EXCEPTION THROWN HERE!
              byte ba[] = rs.getBytes("SitePicture");            
              return new sun.misc.BASE64Encoder().encodeBuffer(ba);
          }
          else {return null;}
      } catch (Exception ex) {
          ex.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>The method above, in the instance the exception was thrown, is taking a genuine siteID (22379) from an Entity object pulled directly from the same table. When using <code>System.out.println(siteID);</code> during this method, it declared that number to still be correct, ie still 22379. I've checked directly with the SQL server by running an identical statement in SQL Server, so I know the row exists in the table, but for some reason it is not being found. Image below.</p>
  
  <p><img src="https://i.stack.imgur.com/NzOyT.png" alt="enter image description here"></p>
  
  <p>So the problem is, the ResultsSet <code>rs</code> is not finding the row even though I know that it's there. Does anyone have any helpful insights?</p>
  
  <p>Clarification: <em>Just to be clear, I know that the ResultsSet contains no rows and that is why I am getting the exception. I also know that putting the rs.next() into the if statement will prevent the exception (as already stated in the comments). What is puzzling me is that the fact the ResultsSet contains no rows even though a row with the ID being parsed to it verifiably does exists because I have checked it directly with the SQL server.</em></p>