cbmeeks
cbmeeks

Reputation: 11420

How do I get the resultset of a stored procedure in JPA?

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

Upvotes: 2

Views: 5463

Answers (1)

cbmeeks
cbmeeks

Reputation: 11420

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.

Upvotes: 4

Related Questions