Stored Procedure returning just one row

Hi! I've a problem with a MSSQL Stored Procedure. This procedure works perfectlly if I execute it directly on MSSQL Query Analyzer. But the problem is in Java, when I call it, the resultset has just one row, and it must have 59, so I don't know what is going on. My procedure is a bit big, but please, help me :)
This is the procedure code
CREATE PROCEDURE desc_doctos
@pt_gaveta varchar(250),
@pl_idexp varchar(250),
@pl_idcar numeric,
@identa int
AS
DECLARE @id_carpeta_hija int
DECLARE @nombre_hija varchar(500)
DECLARE @fh_creacion datetime
DECLARE @numero_carpetas int
DECLARE @numero_documentos int
DECLARE @cv_aplicacion_des varchar(100)
DECLARE @id_gabinete_des int
DECLARE @identa_modificado varchar(10)
DECLARE @liga varchar(250)
DECLARE @hora varchar(50)
DECLARE @fecha varchar(50)
DECLARE imx_descendencia CURSOR LOCAL FOR
SELECT IOC.ID_CARPETA_HIJA, IOC.NOMBRE_HIJA,IC.FH_CREACION,
convert(varchar(2),datepart(dd,IC.FH_CREACION))+'/'+convert(varchar(2),datepart(mm,IC.FH_CREACION))+'/'+convert(varchar(4),datepart(yyyy,IC.FH_CREACION)),
convert(varchar(2),datepart(hh,IC.FH_CREACION))+':'+convert(varchar(2),datepart(mi,IC.FH_CREACION))+':'+convert(varchar(2),datepart(ss,IC.FH_CREACION)),
IC.NUMERO_CARPETAS,IC.NUMERO_DOCUMENTOS,
ICP.CV_APLICACION_DES,ICP.ID_GABINETE_DES
FROM IMX_ORG_CARPETA IOC, IMX_CARPETA IC, IMX_CARPETAPUENTE ICP
WHERE
IOC.TITULO_APLICACION=@pt_gaveta
AND IOC.ID_GABINETE= @pl_idexp
AND IOC.TITULO_APLICACION = IC.TITULO_APLICACION
AND IOC.ID_GABINETE = IC.ID_GABINETE
AND IOC.ID_CARPETA_HIJA = IC.ID_CARPETA
AND IOC.TITULO_APLICACION *= ICP.TITULO_APLICACION                
AND IOC.ID_GABINETE *= ICP.ID_GABINETE
AND IOC.ID_CARPETA_HIJA *= ICP.ID_CARPETA
AND ID_CARPETA_PADRE= @pl_idcar;
OPEN imx_descendencia
     FETCH NEXT FROM imx_descendencia INTO @id_carpeta_hija,@nombre_hija,@fh_creacion,@fecha,@hora,
          @numero_carpetas,@numero_documentos,@cv_aplicacion_des,@id_gabinete_des
     WHILE @@FETCH_STATUS = 0
     BEGIN
          SELECT @identa_modificado = @identa+1          
          IF (@id_gabinete_des IS NOT NULL)
          BEGIN
               SET @liga = '../jsp/imxvisor.jsp?gaveta='+@cv_aplicacion_des+'&idExp='+convert(varchar(10),@id_gabinete_des)+'&cierre=si'     
               BEGIN TRAN
                    --INSERT INTO IMX_ARBOL_TEMPORAL VALUES(@nombre_hija,@liga,@identa,0,'_blank','1',1,1)          
                    SELECT @nombre_hija,@liga,@identa,0,'_blank'
                    EXEC lista_doctos @pt_gaveta,@pl_idexp,@id_carpeta_hija,@identa_modificado
               COMMIT TRAN
          END
          ELSE
          BEGIN
               SET @liga = '../jsp/datosarbol.jsp?opcion=0&idcarpeta='+convert(varchar(10),@id_carpeta_hija)+'&carpetas='+convert(varchar(10),@numero_carpetas)
               SET @liga = @liga + '&documentos='+convert(varchar(10),@numero_documentos)+'&hora='+@hora
               SET @liga = @liga + '&fecha='+@fecha+'&idExp='+@pl_idexp+'&gaveta='+@pt_gaveta
               BEGIN TRAN
                    --INSERT INTO IMX_ARBOL_TEMPORAL VALUES(@nombre_hija,@liga,@identa,0,'DATOS','1',1,1)
                    SELECT @nombre_hija,@liga,@identa,0,'DATOS'
                    EXEC lista_doctos @pt_gaveta,@pl_idexp,@id_carpeta_hija,@identa_modificado
               COMMIT TRAN
          END
          EXEC desc_doctos @pt_gaveta,@pl_idexp,@id_carpeta_hija,@identa_modificado
          FETCH NEXT FROM imx_descendencia INTO @id_carpeta_hija,@nombre_hija,@fh_creacion,@fecha,@hora,
               @numero_carpetas,@numero_documentos,@cv_aplicacion_des,@id_gabinete_des
     END
CLOSE imx_descendencia
DEALLOCATE imx_descendencia
and this is my java code
import java.sql.*;
public class pruebasSQL{
     public static void main(String[] args){
          try{
               Class.forName("com.inet.tds.TdsDriver").newInstance();     
               Connection connection;
               connection = DriverManager.getConnection("jdbc:inetdae7:localhost","user","pass");
               connection.setCatalog( "DataBase");
               CallableStatement statement = connection.prepareCall("{call desc_doctos ('NVA_EST',1002,0,1)}");
               ResultSet rs = statement.executeQuery();
               rs.last();
               System.out.println(rs.getRow());
               rs.close();
               connection.close();
          catch(Exception e){
               System.out.println(e);
Hope u can help me =)
Raul Medina
[email protected]

Hi! I managed to resolve this problem. This is what I did, hope somebody finds it usefull
//connection, declarations, etc...
PreparedStatement ps = connection.prepareStatement("exec desc_doctos 'NVA_EST',1002,0,1");
               ResultSet rs = ps.executeQuery();
               rs.next();
               System.out.println(rs.getString(1));
               while(ps.getMoreResults()){
                    rs = ps.getResultSet();
                    rs.next();
+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4)+" "+rs.getString(5));
                    System.out.println(rs.getString(1));
------------

Similar Messages

  • If the result from the stored procedure returns 0 rows I get this error returned:

    If the result from the following stored procedure returns 0
    rows I get this error returned:
    faultCode:Server.Processing faultString:'Variable transfers
    is undefined.' faultDetail:''
    How can I get round this?

    Well if I try this in a cfm page:
    <cfstoredproc procedure="GetTransfers"
    datasource="datasource" returncode="true">
    <cfprocparam type="in" cfsqltype="CF_SQL_VARCHAR"
    value="4">
    <cfprocparam type="in" cfsqltype="cf_sql_date"
    value="12/09/2006 08:42:00">
    <cfprocparam type="in" cfsqltype="cf_sql_date"
    value="12/09/2008 08:42:00">
    <cfprocresult name="transfers">
    I get an error like:
    [Macromedia][SQLServer JDBC Driver][SQLServer]Procedure or
    function 'GetTransfers' expects parameter '@fromdate', which was
    not supplied.
    But this procedure only accepts 3 parameters.

  • Percentage pie chart whose query return just one value

    Hi,
    I have a requirement which is to display a pie chart that shows the relative percentage of based on a particular row's values.
    Here the SQL query return just one value to generate the chart, however Apex is creating its own seemingly random value to draw the rest of the chart and dividing the region.
    Is there any way for Apex to take the single value that the query returns as a percentage and generate the chart by calculating the other value to be as (100 - queried value) and split the region in the chart accordingly.
    Of course one method is to store both the value that the query returns as well as 100 - that value in a table and then write the query in the chart that references both these values.. but I'd like to know if there is a way to go about it without storing this extra bit of information in a table
    Thanks!

    you create a hidden page item and populate with total value and percentile calculated value and use it in dial chart as querry.

  • SSRS - Oracle Stored procedure returns no data but does in SQL Developer Sudio

    HI there,
    Stored procedure returns no data when executed on the report but when i execute the stored procedure in Sql Developer it returns required rows.
    Thanks for your help!

    Hi Simon,
    When i test with simple query, i get the data.
    For your convenience, my stored proc looks lyk :
    PROCEDURE pr_REPORT_data(P_STARTDATE IN DATE, P_ENDDATE IN DATE, data_rows OUT T_CURSOR) AS 
    OPEN completed_Reinstatement FOR
      SELECT 
                 value1,.......value5
      FROM table1
    WHERE
        To_Date(createdDate, 'YYYY/MM/DD') BETWEEN To_Date(P_STARTDATE, 'YYY/MM/DD') AND To_Date(P_ENDDATE, 'YYYY/MM/DD');
    END pr_REPORT_data;          
    T_CURSOR is of type cursor which is declared on the package.
    I'm assuming the problem is with date parameters, however i converted the date before passing to
    WHERE clause. 

  • Problem calling Stored Procedure returning SETOF UDT (Using Spring)

    I am using Spring's StoredProcedure class to call a stored procedure from a PostgreSql database. It returns a set of user defined data types. I'm having a problem in parsing the results returned.
    The user defined data type :
    CREATE TYPE process_states AS (
    process_name text,
    process_type text
    The stored procedure returns a SET of "process_state" :
    CREATE FUNTION inquire_process_state (.....)
    RETURNS SETOF process_state AS '
    SELECT ....
    I hava a Java class extending the Spring StoredProcedure classs.
    public MyProcStats extends StoredProcedure {
    private class ProcStateCallBackHandler implements RowCallBackHandler {
    public void processRow(ResultSet rs) throws SQLException {
    System.out.println(rs.getString(1));
    public MyProcStats (DataSource ds) {
    super(ds, "inquire_process_state");
    super.setFunction(true);
    declareParameter(new SqlOutparameter("rs", Types.OTHER, new ProcStateCallBackHandler());
    declareParameter(new SqlParameter("family_name", Types.VARCHAR) ;
    While testing this class, I get an errormessage
    "java.sql.SQLException:ERROR: cannot display a value of type record"
    I would appreciate if anyone can point out my mistakes. I tried declaring
    new SqlOutParameter("rs", Types.OTHER, "process_state"), but that didn't help.

    As the related posts suggest, you will need to use direct JDBC code for this.
    Also I'm not sure JDBC supports the RECORD type, so you may need to wrap your stored functions with ones that either flatten the record out, or take OBJECT types.

  • Error when linking report to stored procedure defined with one input parm

    Error when linking report to stored procedure defined with one input parameter
    The report will work ok, when the parameter is removed from the stpred procedure
    An unhandled win32 exception occurred in crw32.exe[4480]
    Stored Proc (sql server 2005)
    USE [Allegro]
    GO
    /****** Object:  StoredProcedure [dbo].[SP_Test]    Script Date: 07/08/2009 10:42:14 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER procedure [dbo].[SP_Test](@valuationmode VARCHAR(55)) as
    Begin
    select
         valuation,
         valuationtime,
         valuationmode
    from valuation
    where valuationmode = @valuationmode;
    End;

    This is an example of a stored procedure that is trying to be linked to a new report as the only datasource.
    If I remove the parameter I can create a report, however this will return all of the results of thw query to the report, rather than the desired results. If I add the parameter on the Crystal Report, the stored procedure then has to return all of the results to Crystal and then perform the filtering of records. By using a parameter in the stored procedure, you should be able to do all of the filtering as part of the query on the databse server, making this more efficient.

  • Adding Just One Row at a Time

    Multiple users can add Comments to a table, once added, the comments should be read only. How would I go about creating a region that will add just one row at a time, clear the region and then allow the adding of another row and not allow access to existing data rows?
    Jeff

    This example is doing exactly that:
    http://apex.oracle.com/pls/otn/f?p=31517:170
    Once added, the row can not be changed any more.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • Error in calling Stored procedure returns REFCURSOR

    Hi,
    I've written a oracle stored procedure returning REFCURSOR. say,extractorderdespatchconfirmsp('','','','','','H1','ACG','','','','',:rc).
    Following statement throwing error.
    CallableStatement cs = con.PrepareCall("{extractorderdespatchconfirmsp('','','','','','H1','ACG','','','','',:rc)}");
    rs = cs.executeQuery();
    Could you rectify this problem and give me the currect code.
    riyaz

    Your naming convention leaves a little to be desired.
    String command = "{CALL extractorderdespatchconfirmsp(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
    CallableStatement cstmt = conn.prepareCall(command);
    //set the variables here ie, dates need to be a timestamp format. use set timestamp.
    cstmt.setInt(1, 2);
    cstmt.setString(2, "a string");
    cstmt.setInt(3, 0);
    //for return values
    cstmt.registerOutParameter(3, Types.INTEGER);
    cstmt.registerOutParameter(2, Types.INTEGER);
    cstmt.execute();
    int status = cstmt.getInt(3);
    int status2 = cstmt.getInt(2);
    cstmt.close();
    It took me awhile too to get JDBC to call these right.

  • Error saving map. Stored procedure returned non-zero result BizTalk Bug

    Hallo all
    MSDN is reporting this Bug.
    "Error saving map. Stored procedure returned non-zero result." error message when you deploy the BizTalk Server 2010 applications in BizTalk Server 2010 Administration Console"
    http://support.microsoft.com/kb/2673264/en-us
    I am having this problem in BizTalk 2013. Is this correct? or I am doing something wrong..
    This error occured as I was about to deploy BizTalk application from Visual studio 2012 to BizTalk 2013.
    If this bug is available in 2013, where can I get a fix for it..
    Thanks in Advance
    AKE

    Hi AKE,
    Fix for this bug in BizTalk Server 2013 is not publicly available yet. Only option to get the fix for this bug is to contact:
    http://support.microsoft.com/contactus/?ws=support
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful.

  • Error saving map. Stored procedure returned non-zero result. Check if source and target schemas are present.

    I am using VS 2012 and BizTalk 2013 and attempting to deploy an application to BizTalk when I get these errors:
    Error 47
    at Microsoft.BizTalk.Deployment.Assembly.BtsMap.Save()
       at Microsoft.BizTalk.Deployment.Assembly.BtsArtifactCollection.Save()
       at Microsoft.BizTalk.Deployment.Assembly.BtsAssembly.Save(String applicationName)
       at Microsoft.BizTalk.Deployment.BizTalkAssembly.PrivateDeploy(String server, String database, String assemblyPathname, String applicationName)
       at Microsoft.BizTalk.Deployment.BizTalkAssembly.Deploy(Boolean redeploy, String server, String database, String assemblyPathname, String group, String applicationName, ApplicationLog log)
    0 0
    Error 49
    Failed to add resource(s). Change requests failed for some resources. BizTalkAssemblyResourceManager failed to complete end type change request. Failed to deploy map "XXX.BTS2013.XXX.Maps.map_XXXX_R01_InsLabProc".
    Error saving map. Stored procedure returned non-zero result. Check if source and target schemas are present. Error saving map. Stored procedure returned non-zero result. Check if source and target schemas are present.
    0 0
    Error 46
    Failed to deploy map "XXX.BTS2013.XXX.Maps.map_XXXX_R01_InsLabProc".
    Error saving map. Stored procedure returned non-zero result. Check if source and target schemas are present.
    0 0
    I also tried to Import a MSI file from our test environment to see if that would work...got the same errors.  After spending hours (not kidding) looking for an answer, all I could find is that a hotfix would work.  So, I got the hotfix from Microsoft
    Support and applied it then rebooted.  Still getting the same errors.  I'm absolutely at a stand still.  Interesting that I got this application to deploy yesterday and then the next time I deployed it I started getting these errors.  I'm
    ready to pull my hair out!
    Is there an answer for this out there somewhere?  Any help would be appreciated.
    Thanks,
    Dave

    Hi Dave,
    Which hotfix have you applied? I don't think a hotfix of this issue is available for BizTalk 2013 yet. You should create a
    support ticket with Microsoft to get a solution.
    If this answers your question please mark as answer. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • I have 3 drop down boxes in my report done SQL SSRS .. I want t to put them in the same row (just one row) ..how can I do it.?

    I have 3 drop down boxes in my report done SQL SSRS .. I want t to put them in the same row (just one row) ..how can I do it.?

    Hi Sashi123,
    Just as Ivan said, we do not have the ability to change the Report Manager in this way. Because we can’t change the parameters locations as this is not supported to write expressions for the location of parameters.
    While we can build a custom application in Visual Studio that we can get it through codes after deploying the report, then through URL we can get it by customization.
    Hope this helps.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Pages won't allow me to create a table with just one row.

    I'm trying to create a one row, two colum table in Pages. I have no problem with the columns. But I cannot create the table with just one row. Two rows apppears to be the minimum. Any ideas??

    In Pages 5.2, click the equal sign at bottom-left of table and reduce the row count to one.

  • Stored Procedure Returning Multiple Rows

    Hello. Where can I find sample code from a class that calls a stored procedure that returns multiple rows?
    I have a servlet that calls the DB directly from the servlet & loops through the result set. I want to put that code into a stored procedure, but I'm not sure how to loop through the results.
    Your help is greatly appreciated!

    Surely you would call the stored procedure and loop
    through the resultset as usual.
    all that is different is the method by which you obtain the resultSet .
    assuming CallableStatement, Connection have been
    instantiated.
    cstmt=con.prepareCall("{call sp_NewOfficeSurgery (?,?)}");
    cstmt.setString(1,"first");
    cstmt.setString(2,"second");
    rs = cstmt.executeQuery();
    while (rs.next())
    String nme = rs.getString(1)
    etc,etc
    Hope this helps , Sorry If I have misinterpreted this
    please let me know if my thinking is floored or you need
    further clarification ect.
    [email protected]

  • Stored procedure return datatable or temporary table

    hi again everybody
    i just want to ask can stored procedure or function return a datatable or a temporary table that i want to fill later
    the problem is i want to make a stored procedure that make research for the client with many option and with this selected option the procedure execute the right request from
    different table and i just return the result in the datatable or the temporary table ????
    help ^^ and thank's

    >
    so i want make the client choose options for search and after that the programme interrogate my DB according to his options
    so the solution i want it ,i hope it's optimised cuz i dn't want to use much view or cursor so when i interrogate the BD i put the result into temporary table
    >
    Well that is a start at a better explanation though you still seem focused on the solution you want instead of the result you want. It shouldn't matter to you if a view or cursor is used if you get the result quickly. Besides all queries use cursors to get their results whether you explicitly define a cursor or not.
    The usual choices given to users for any particular search do not include which table or view to use. You would normally let the user select the filtering to be done.
    The columns and datatypes in the result set are usually fixed and are not provided dynamically. That is you wouldn't let user1 select 5 columns from tableA and user2 select 7 different ones. The reason is the the client software used to display the result set to the user needs to know how many columns it has to deal with and what the datatypes are.
    Only software like sql developer, toad or similar creates generic data grids with different columns and datatypes.
    >
    and that so the other thing i want is : can stored procedure or function return a datatable
    >
    As Justin said a pipelined function can return a result set but, like I just said above, it generally returns the same number of columns and the same datatypes every time it is called. A procedure can return a REF CURSOR that the client software can use to obtain the rows of the result set or the procedure could return an Oracle collection.
    But procedures/functions don't return actual tables. Returning a small collection is as close to that as you get.

  • Query against materialized view from stored procedure brings back empty row

    I have a stored procedure that runs a query against a materialized view. When I run the query outside the SP it works just fine. When I change the MV to a table name, the SP works. When I change it back to the MV i get an empty row. Any ideas? The code is below:
    PROCEDURE getAuth     (p_naid        IN  NUMBER,
                             p_scope       IN VARCHAR2,
                             o_xml_data    OUT SYS_REFCURSOR
                             ) IS
      BEGIN
        IF p_scope = 'Approved' THEN
          OPEN o_xml_data FOR
            SELECT naid,
                   p_naid,
                   auth_type,
                   xml_data
            FROM some_mv
            WHERE naid = p_naid;   
          RETURN;
          CLOSE o_xml_data;
    ... the rest of the procedure ...

    does procedure contain EXCEPTION handler?
    if so, then remove, delete & eliminate EXCEPTION handler (at least during testing & debugging)

Maybe you are looking for

  • Execute owb mapping as a whole instead of giving step by step or skip

    Hi friends, I need a help from you.. Actually i am working with owb 10.2 and db 10.2. I am able to do all the process successfully like debugging, reinitializing and entering the data into the table. The thing is while debugging,i have to give step o

  • ITunes 11 wifi sync problem

    Hi all, I just update to iTunes 11, but since than I'm only able to sync my iPad and iPhone with a cable, the wifi sync option is not working. Both of my iDevices won't find my MacBook Info: iPad Wifi 3rd Gen iPhone 5 MacBook Pro 15" (mid 2011) Hope

  • My HP all in one is acting up-it is 10 months old. All of a sudden there is no picture when I start

    I can hear the sound of start up and the picture comes on for a second and then it goes black. Can't log in or even touchyng the screen doesnt work? I use Windows 7 and have not done any upgrades or downloaded anything

  • Adobe AIR Application Installer.exe

    On my win xp pro sp3 machine from all the Adobe stuff following software installed only: - acrobat reader - flash player - shockwave player The Secunia scan tool noticed me recently I had old version of flash player. It is not right, some days ago ju

  • Merge Organizations

    Hi, We've implemented Oracle Projects and Oracle Financials. We have setup 5 organizations (departments) in HR which have the classifications: HR Organization Project Task Owning Organization Project Expenditure Organization The orgnaizations in HR a