Data service does not return TSQL generated exception

muckypup's picture
Using a Microsoft database and the microsoft jdbc drivers, if I do a RAISEERROR within my data service query it is ignored and an empty resultset returned. How can I capture and return TSQL exceptions? Steve
daggett's picture

Data service does not return TSQL generated exception

this is due to the way how WSO2 DS process procedure call. as for me, this is a bug. if the first keyword of sql command is SELECT, then errors are displayed correctly. if you could present your procedure as a function and then do a select, like this: select * from your_function() then you will solve the problem
muckypup's picture

We only used SP's to talk to

We only used SP's to talk to the DB. The lines are usually EXEC p_proc @param1 = ?, @param2 = ? It's a bit more complex if we have an out parameter. the only way I could get it to work was to something similar to the following. DECLARE @id int; EXEC p_proc @param1 = ?, @param2 OUTPUT; SELECT @param2 AS id In fact there is another bug in this area. if SP p_proc does not return any value (ie is a simple update, and does not select any rows) then an exception is thrown in the DS. To get around this we have to do something similar to the following.. EXEC p_update @param1 = ?, @param2 = ? SELECT 1 AS DUMMY Steve
muckypup's picture

Issue Found

In addition, we have investigated the code and found the issue. The solution has been submitted back into the system for review. https://wso2.org/jira/browse/CARBON-3731 You can d/l a patch for DButils.java if you fancy building it yourself. Steve
daggett's picture

procedure processing suggestion

i sure the following code is faulty in 90% : try { rs = cs.executeQuery(); } catch (SQLException e){ if(e.getMessage().indexOf("bla-bla")>-1) cs.executeUpdate(); else throw new exception; } -- 1. this code could execute procedure two times 2. for oracle it is not working ( cs.executeQuery() returns resultset that crashed on rs.next() ) -- I propose the following code: if ( !cs.execute() ) { //the first result is an update count or there is no result //skip update counts until first resultset //maybe for saome databases it's required to take next line in try-catch and ignore exception. while( cs.getUpdateCount()!=-1 ); } if( cs.getMoreResults() )rs=cs.getResultSet(); else noResultSet = true;
library project main code
Learn Cloud
Learn
Cloud

The WSO2 Application Server is a reliable application server that can host your enterprise web applications. The WSO2 Application Server as a Service is offered in StratosLive, the WSO2 Platform as a Service. This article explains how a simple web application can be developed and deployed from Carbon Studio to the WSO2 Application Server...

Latest Webinar
Different groups within an organization need to monitor different Key Performance Indicators (KPIs) - An operations team will be interested in the response times of business services and loads of each service,..
Thursday, February 9th 2012, 09.00 AM (PST)

Thursday, February 9th 2012, 10.00 AM (GMT)