How to return a result set from a web service in java

I am writing an application in which I create web services. I create an operation (method) that retrieves the values ​​of a database table from a database table in a result set. Therefore, we cannot return the resultet value directly in web services. I am creating a class that contains values ​​from a result set. instead of resultet, I return the object [] of the newly created class as follows:

 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;
    }

but when trying to access these values ​​in the web service client, it sends a java.lang.NullPointerException.

here is the code that I use in the web service client to access the result set of the value:

    public void get_HistoryInfoByUser(String email_Id) 
{      
               service = new DBService();

               port = service.getDBPort();

    try {

        List<HistoryInfoByUser> 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);
    }

 }

, (HistoryInfoByUser) [] (HistoryInfoByUser []). , NullPointerException, []. , .

, .

+5
3

WebRowSet -:

import javax.sql.rowset.WebRowSet;
import com.sun.rowset.WebRowSetImpl; // Reference implementation
...
// get ResultSet rs from db
WebRowSet wrs = new WebRowSetImpl();
wrs.populate(rs);
// return wrs from web service

, JDBC WebRowSet . .

+2

historyIn[rowCounter] = new HistoryInfoByUser();

while. , . , , .

gpeche , , .

+1

ResultSet - Java.

ResultSet , .

; .

+1

All Articles