java - EclipseLink SQLServerException when returning stored procedure without result set -


i using eclipselink 2.4.2 call stored procedure in sql server database. stored procedure legacy code have no insight.

storedprocedurecall call = new storedprocedurecall(); call.setprocedurename("p_get_sales"); call.addnamedargument("p_part", "part") call.addnamedargument("p_product_nr", "productnr") call.addnamedargument("p_lang", "lang")  datareadquery query = new datareadquery(call); query.addargument("part") query.addargument("productnr") query.addargument("lang");  jpaentitymanager jpaem = em.unwrap(jpaentitymanager.class); list<arrayrecord> records = (list<arrayrecord>) jpaem.getactivesession().executequery(query, arrays.aslist(part, productnr, lang)); 

all fine if data available result set returned procedure. there not exist data in database returned. in case following exception:

exception [eclipselink-4002] (eclipse persistence services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.databaseexception internal exception: com.microsoft.sqlserver.jdbc.sqlserverexception: statement did not return result set. error code: 0 call: execute p_get_sales @p_part = ?, @p_product_nr = ?, @p_lang = ?     bind => [total, 5, de] query: datareadquery()     @ org.eclipse.persistence.exceptions.databaseexception.sqlexception(databaseexception.java:333)     @ org.eclipse.persistence.internal.databaseaccess.databaseaccessor.basicexecutecall(databaseaccessor.java:646)     @ org.eclipse.persistence.internal.databaseaccess.databaseaccessor.executecall(databaseaccessor.java:537)     @ org.eclipse.persistence.internal.sessions.abstractsession.basicexecutecall(abstractsession.java:1805)     @ org.eclipse.persistence.sessions.server.serversession.executecall(serversession.java:566)     @ org.eclipse.persistence.internal.queries.datasourcecallquerymechanism.executecall(datasourcecallquerymechanism.java:207)     @ org.eclipse.persistence.internal.queries.datasourcecallquerymechanism.executecall(datasourcecallquerymechanism.java:193)     @ org.eclipse.persistence.internal.queries.datasourcecallquerymechanism.executeselectcall(datasourcecallquerymechanism.java:264)     @ org.eclipse.persistence.internal.queries.datasourcecallquerymechanism.executeselect(datasourcecallquerymechanism.java:246)     @ org.eclipse.persistence.queries.datareadquery.executenoncursor(datareadquery.java:197)     @ org.eclipse.persistence.queries.datareadquery.executedatabasequery(datareadquery.java:152)     @ org.eclipse.persistence.queries.databasequery.execute(databasequery.java:852)     @ org.eclipse.persistence.queries.datareadquery.execute(datareadquery.java:137)     @ org.eclipse.persistence.queries.databasequery.executeinunitofwork(databasequery.java:751)     @ org.eclipse.persistence.internal.sessions.unitofworkimpl.internalexecutequery(unitofworkimpl.java:2879)     @ org.eclipse.persistence.internal.sessions.abstractsession.executequery(abstractsession.java:1607)     @ org.eclipse.persistence.internal.sessions.abstractsession.executequery(abstractsession.java:1589)     @ org.eclipse.persistence.internal.sessions.abstractsession.executequery(abstractsession.java:1554)     caused by: com.microsoft.sqlserver.jdbc.sqlserverexception: statement did not return result set.     @ com.microsoft.sqlserver.jdbc.sqlserverexception.makefromdrivererror(sqlserverexception.java:190)     @ com.microsoft.sqlserver.jdbc.sqlserverpreparedstatement.doexecutepreparedstatement(sqlserverpreparedstatement.java:408)     @ com.microsoft.sqlserver.jdbc.sqlserverpreparedstatement$prepstmtexeccmd.doexecute(sqlserverpreparedstatement.java:350)     @ com.microsoft.sqlserver.jdbc.tdscommand.execute(iobuffer.java:5696)     @ com.microsoft.sqlserver.jdbc.sqlserverconnection.executecommand(sqlserverconnection.java:1715)     @ com.microsoft.sqlserver.jdbc.sqlserverstatement.executecommand(sqlserverstatement.java:180)     @ com.microsoft.sqlserver.jdbc.sqlserverstatement.executestatement(sqlserverstatement.java:155)     @ com.microsoft.sqlserver.jdbc.sqlserverpreparedstatement.executequery(sqlserverpreparedstatement.java:285)     @ org.eclipse.persistence.internal.databaseaccess.databaseaccessor.executeselect(databaseaccessor.java:938)     @ org.eclipse.persistence.internal.databaseaccess.databaseaccessor.basicexecutecall(databaseaccessor.java:609)     ... 47 more 

what have avoid exception in case there no result set returned?

try , catch?

list<arrayrecord> records; try{ list<arrayrecord> records = (list<arrayrecord>) jpaem.getactivesession().executequery(query, arrays.aslist(part, productnr, lang)); }catch(databaseexception ex){  records = new arraylist<arrayrecord>(); return records; //return empty list, or can handle own exception } 

it specific driver exception, must handle (it not common empty resultset).

if query doesn't execute select operation, executes either insert, update, or delete operation, use executupdate instead of executequery, therefore preventing driver exception.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -