2

I have SQL Server 2008 and a JPA (EclipseLink) app. I need to be able to read the rows from the stored procedure. The stored procedure does some updating/etc but at the end returns a

select * from @result_table

Now, when I access it in JPA using:

String sql = "exec up_GetUpdatedRows ?, ?, ?";
entityManager = Factories.getEntityManager();

Query query = entityManager.createNativeQuery(sql);
query.setParameter(1, myKey).setParameter(2, workDate).setParameter(3, createdBy);

List<Object[]> obj = query.getResultList();

I get the following error:

Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.

This works for other native SQL.

Any ideas?

Thanks

cbmeeks
  • 11,248
  • 22
  • 85
  • 136
  • 1
    This does not appear to be related to JPA. This seems to be more related to the underlying JDBC driver. Check this other [question/answer](http://stackoverflow.com/questions/1826271/sqlserverexception-the-statement-did-not-return-a-result-set-when-executing-sql). This person reports the same problem as you. Perhaps the answers also works for you. – Edwin Dalorzo Jun 08 '11 at 19:49

1 Answers1

4

After a lot of trial and error, I finally found this answer. I found it from another question here.

The problem was with not using SET NOCOUNT ON. It was very confusing as the error said there were no result sets. Yet, there appeared to be many.

Community
  • 1
  • 1
cbmeeks
  • 11,248
  • 22
  • 85
  • 136