title: How to return result sets from Stored Procedure?
body: <p>I created a Stored Procedure where I can fetch all my data that I inserted in my following textfields. How can I fetch all of this data by calling my Callable Statement? I think this is the easiest way than Batch Statement based on what I read. I only drag and drop this following components just a practice purposes.</p>
  
  <p><strong>Stored Procedure</strong></p>
  
  <pre><code>CREATE PROCEDURE show_data(OUT FULLNAME VARCHAR(50), OUT ADDRESS VARCHAR(50))
  PARAMETER STYLE JAVA
  LANGUAGE JAVA
  READS SQL DATA
  DYNAMIC RESULT SETS 1
  EXTERNAL NAME 'Frame.searchButton'
  </code></pre>
  
  <p>I used OUT parameter to retrieve values using getXXX() methods. I'm just little bit confuse since this is my first time to use Stored Procedure in derby. </p>
  
  <p><strong>GUI</strong></p>
  
  <p><a href="https://i.stack.imgur.com/08rpW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/08rpW.png" alt="enter image description here"></a></p>
  
  <p>After the user search the following record in Database. If the value exist it will print to the designated textfields.</p>
  
  <p><strong>SOURCE CODE</strong></p>
  
  <pre><code>    String searchRecord = searchTf.getText();
  
      String searchQuery = "SELECT * FROM SAMPLEONLY";
      ResultSet data[] = null;//Why should I use this array?
  
      try (Connection myConn = DriverManager.getConnection(url, user, pass);
          PreparedStatement myPs = myConn.prepareStatement(searchQuery);)
          {
              String addFullname = fullnameTf.getText();//first field
              String addAddress = addressTf.getText();//second field
  
              data[0] = myPs.executeQuery();
  
              CallableStatement cs = myConn.prepareCall("{ call showData(?, ?)}");
  
              cs.setString(1, addFullname);
              cs.setString(2, addAddress);
  
              boolean hasResults = cs.execute();
              if (hasResults) {
              ResultSet rs = cs.getResultSet();
              while (rs.next()) {
                  String getFullname = rs.getString(1);//get the value
                  String getAddress = rs.getString(2);
  
                  fullnameTf.setText(getFullname);//set the text here
                  addressTf.setText(getAddress);  
              }//end of while
              rs.close();//close the resultset
          }//end of if
      }//end of try
          catch (SQLException e) 
          {
              e.printStackTrace();
          }
      }//end of else
  }
  </code></pre>
  
  <p>After I insert in Search textfields it throws me a error NullPointerExeption. I follow Derby Reference Manual so I can have a guide writing a proper Stored Procedure. This code is mine most of the part. Guide me if I missed something wrong. Feel free to comment thanks.</p>