title: exception occurs when I want to retrieve data that is not present in the database
body: <p>I use JDBC to store my data in my SQL database. When I want to retrieve the data, it gives an exception. the code to retrieve the data is</p>
  <pre class="lang-java prettyprint-override"><code>    public Stoke getCurrantStokeByBarcode(String barcode)
      {
          String query = &quot;SELECT * FROM stoke WHERE barcode =?&quot;;
          try {
              PreparedStatement preparedStatement = connection.prepareStatement(query);
              preparedStatement.setString(1,barcode);
              ResultSet resultSet = preparedStatement.executeQuery();
              resultSet.absolute(1);
              if (resultSet != null)
              {
                  if (resultSet.getString(1).equals(barcode)) {
                      Stoke item = new Stoke(resultSet.getString(2),resultSet.getString(4),
                              resultSet.getString(3),resultSet.getString(1)
                              ,resultSet.getString(5),resultSet.getString(7),
                              resultSet.getString(6),resultSet.getString(8)
                              ,resultSet.getString(9));
      
                      return item;
                  }
              }
              else
                  return null;
          } catch (SQLException throwables) {
              throwables.printStackTrace();
          }
          return null;
      }
  </code></pre>
  <p>I also included a check to for this exception, but it still occurs. How do I remove this exception?</p>
  <pre><code>    java.sql.SQLException: Illegal operation on empty result set.
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
          at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:780)
          at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5204)
          at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5127)
          at sample.Database.DatabaseHandler.getCurrantStokeByBarcode(DatabaseHandler.java:79)
          at sample.Controller.Add_StokeController.onBarcodeScan(Add_StokeController.java:218)
          at jdk.internal.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
  </code></pre>