title: How to return resultset from web service in java
body: <p>i am writing an application in which i am creating web services. i am creating an operation(method) which retrieves database table values from database table in resultset. Hence we can't return resultset value directly in web services. i am creating a class which holds the values from resultset. instead of resultset i am returning object[] of newly created class as follows :</p>
  
  <pre><code> public HistoryInfoByUser[] get_HistoryInfoByUser(@WebParam(name = "email_Id")
    String email_Id) throws Exception{
  
          HistoryInfoByUser[] historyIn = null;
          if (conn != null) {
          CallableStatement cst = conn.prepareCall("{call sp_xxxx(?)}",ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
              cst.setString(1, email_Id);
              ResultSet resultSet = cst.executeQuery();
               int rowCount = resultSet.getRow();
  
             historyIn = new HistoryInfoByUser[rowCount];
  
            while (resultSet.next())
               {
  
                  historyIn[rowCounter].setId(rowCounter);                               
             historyIn[rowCounter].setStartTime((java.util.Date)resultSet.getObject(1));
                  historyIn[rowCounter].setType((String) resultSet.getObject(2));
  
  
               rowCounter++;
              }
          }
          return historyIn;
      }
  </code></pre>
  
  <p>but while trying to access those values in web service client, it is giving java.lang.NullPointerException.</p>
  
  <p>here is the code that i am using in web service client for accessing resultset
   values :  </p>
  
  <pre><code>    public void get_HistoryInfoByUser(String email_Id) 
  {      
                 service = new DBService();
  
                 port = service.getDBPort();
  
      try {
  
          List&lt;HistoryInfoByUser&gt; historyIn = port.getHistoryInfoByUser(email_Id);
        Iterator iterator = historyIn.iterator();
              while (iterator.hasNext()){
                System.out.print(iterator.next()+" ");  
              }
        } catch (Exception_Exception ex) {
          Logger.getLogger(DataBaseWSHelper.class.getName()).log(Level.SEVERE, null, ex);
      }
  
   }
  </code></pre>
  
  <p>I tried returning a singe row value by returning an object (HistoryInfoByUser) of newly created class instead of object[] (HistoryInfoByUser[] ). It works fine with single object but giving NullPointerException when i am using object[]. i am not getting any way which will help me to overcome with this problem of accessing resultset value.</p>
  
  <p>I thank in advance to your all valuable suggestions which will help me to overcome with this problem.</p>