Retrieve a single row from Multirow ResultsetObject

I would like to know how can i retrieve a single row from a multi row result object. I have a result object which retrieved multiple rows and i would like to retrieve only the top row or a specific row. Can any one of you suggest how this can be done. Thank you for all the help in advance.

call next() on your result set, this goes to the first row and you can retrieve the data with getString(), getInt(), etc.

Similar Messages

  • Retrieve a single row from Oracle function

    Hi!
    I have an Oracle function created as follow:
    CREATE OR REPLACE FUNCTION user_data(userId IN users.user_id%TYPE)
    RETURN users%ROWTYPE AS
    userData users%ROWTYPE;
    BEGIN
    SELECT * INTO userData
    FROM users
    WHERE user_id = userId;
    RETURN userData;
    END user_data;
    This function returns a single row from 'users' table.
    I tried to retrieve that single row by mean of:
    CallableStatement statement = connection
    prepareCall("{ call ? := get_data(?) }");
    statement.*registerOutParameter(1, OracleTypes.OTHER)*;
    statement.setInt(2, 103);
    statement.execute();
    ResultSet rs = (ResultSet) statement.getObject(1);*
    String value = rs.getString(2);
    System.out.println(value);
    But this code doesn't work.
    I tried other OracleTypes, also. (I don't know what OracleType I receive when the Oracle function return a ROWTYPE.)
    Can somebody tell me how to retrieve that single row?
    What is the type of out parameter (registerOutParameter()) when the Oracle function return a ROWTYPE?
    Notes: No cursor can be added. No database change is allowed.
    Thank you in advance.
    [Adrián E. Córdoba]
    Edited by: aecordoba on Mar 18, 2011 3:58 PM

    aecordoba wrote:
    I beg your pardon for my bad English. (It isn't my original language.)
    It's not a language problem. It's that you didn't provide any details about what went wrong.
    That just is my problem:
    I know the retrieved result is not a result set: It's a single row.Doesn't matter if it's a single row. You have a ResultSet object. You have to call ResultSet's next() method to get to the first row, even if it's the only row.
    1- Which is the Oracle type I receive in Java when the Oracle function returns a ROWTYPE?I don't know.
    2- How can I get each column value when I receive a single row in Java?The same way as when there are multiple rows: For each row, call ResultSet.next() to advance to the next row, then call the appropriate ResultSet.getXxx() methods to get each column's value. Again: If you have a ResultSet, you must call next() to get to the first row, even if there is only one row. "First row out of 1 total row" is no different than "first row out of 100 total rows."
    EDIT: Okay, I didn't notice before that you're using a CallableStatement with "out" parameters. I've never used one of those before, so I'm not familiar with the details. I really don't know if casting to a ResultSet is appropriate here. Do you actually have documentation that says you can do that, or are you just guessing and trying to find something that works.
    Edited by: jverd on Mar 18, 2011 11:26 AM

  • Can you retrieve a single row from a user specified SDO theme?

    I am currently trying to add a polygon to my map straight from the database. I have a table of towns blocks, which with the code below will add the the blocks.
    var id = "addBlocks";
    var theme = "data_source.TOWNS_BLOCKS";
    var themeBasedFOI = new MVThemeBasedFOI(id, theme);      
    mapview.addThemeBasedFOI(themeBasedFOI)
    I was wondering if there was a way to select a single block (a particular row from the table) using this method?
    Thanks,
    Higel

    My theme i this case is VIC_BLOCKS. I looked at the Templated Theme Based FOI Layer before, but from what i could tell you need the xml to define the <features>
    This is the javascript code.
    function temlatedThemeBasedFOI() {     
    var themebasedfoi = new MVThemeBasedFOI('id','data_source.VIC_BLOCKS');
    themebasedfoi.setQueryParameters('443');
    mapview.addThemeBasedFOI(themebasedfoi);
    Now i need the xml to define the query.
    <?xml version="1.0" standalone="yes"?>
    <styling_rules>
    <hidden_info>
         <field column="BLOCK_MEMBER" name="Name"/>
    </hidden_info>
    <rule>
    <features style="M.SMALL CIRCLE"> (BLOCK_MEMBER=:1) </features>
    </rule>
    </styling_rules>
    But what is to be done with this xml. I assume it is in a separate xml file. So where do i put it and how does it link to the javascript? Am i on the right track or have i totally misunderstood the situation?
    Thanks,
    Higel

  • Single single row from duplicate

    I have a query that is retrieving duplicate rows the only difference is the date created, so I want to retrieve the most recent. Is there are way to retrieve the most recent. I tried using Max(date) but it doesn't work. Then if that doesn't work, I would like to retrieve a single row, it really doesn't matter. Select Distinct does not work.

    Another possible solution:
    WITH DATA AS (SELECT 'A' COL1, 1 COL2, TRUNC(SYSDATE) DATE_CREATED FROM DUAL
                  UNION ALL
                  SELECT 'B' COL1, 2 COL2, TRUNC(SYSDATE)-1 DATE_CREATED FROM DUAL
                  UNION ALL
                  SELECT 'C' COL1, 3 COL2, TRUNC(SYSDATE)-2 DATE_CREATED FROM DUAL
    SELECT *
    FROM DATA
    WHERE DATE_CREATED = (SELECT MAX(DATE_CREATED)
                                    FROM DATA)Regards,
    Miguel

  • Single row from this query without create a group by

    Can I have a single row from this query without create a group by on tipo (TIPO can have only 2 value (A,D)
    SELECT
    CASE TIPO
    WHEN 'D' THEN SUM(IMPORTO) ELSE 0 END DIMPORTO,
    CASE TIPO
    WHEN 'A' THEN SUM(IMPORTO) ELSE 0 END AIMPORTO
    FROM MGIORNALE
    WHERE K_CONTO = '100001' --CONTO
    AND DECODE(T_MOVIM,'MRAP',TO_DATE('31/12/'||to_char(a_competenza),'DD/MM/YYYY'),DATA_RG)
    -- BETWEEN DATAA AND DATAB
    BETWEEN '01/01/2006' AND '31/12/2006'
    --GROUP BY TIPO
    --AND TIPO = COL_conto
    Thanks in advance

    Is like this?
    sum (CASE TIPO
    WHEN 'D' THEN IMPORTO ELSE 0 END) DIMPORTO,

  • Single row from one-to-many

    I am having trouble with a query, I need a single row from a 1-to-many relationship that is prioritized by certain ID's.
    Department Table - dept_id,dept_name
    Employee Table - emp_id, emp_name
    D-E-Lookup Table - dept_id,emp_id
    Employee ID priority are 5,8,9,21,33,78
    I need each department name with the associated employee name.
    There should be only one row per department.
    If that department does not have empID 5, than 8, if not 8 then 9, if not 9 than 21, etc
    Any help would be greatly appreciated.

    How about this:
    WITH departments AS
        ( SELECT ROWNUM AS deptno, COLUMN_VALUE AS dname
          FROM   TABLE(sys.dbms_debug_vc2coll('Sales','IT','Research')) )
       , employees AS
        ( SELECT ROWNUM AS empno, COLUMN_VALUE AS ename
          FROM   TABLE(sys.dbms_debug_vc2coll('Bennett','Parkman','Nakamura')) )
       , department_assignments AS
         ( SELECT 1 AS deptno, 1 AS empno, 5 AS priority FROM dual UNION ALL
           SELECT 1 AS deptno, 2 AS empno, 8 AS priority FROM dual UNION ALL
           SELECT 1 AS deptno, 3 AS empno, 9 AS priority FROM dual UNION ALL
           SELECT 2 AS deptno, 2 AS empno, 8 AS priority FROM dual UNION ALL
           SELECT 2 AS deptno, 3 AS empno, 9 AS priority FROM dual UNION ALL
           SELECT 3 AS deptno, 1 AS empno, 9 AS priority FROM dual UNION ALL
           SELECT 3 AS deptno, 3 AS empno, 21 AS priority FROM dual )
    SELECT dname, ename, priority
    FROM   ( SELECT d.dname
                  , e.ename
                  , dp.priority
                  , DENSE_RANK() OVER (PARTITION BY d.deptno ORDER BY dp.priority) AS ranking
             FROM   departments d
                    LEFT JOIN department_assignments dp ON dp.deptno = d.deptno
                    LEFT JOIN employees e ON e.empno = dp.empno )
    WHERE ranking = 1;
    DNAME         ENAME             PRIORITY
    Sales         Bennett                  5
    IT            Parkman                  8
    Research      Bennett                  9
    3 rows selectedThe <tt>WITH</tt> clause is just to define test data inline rather than creating tables, in case that's not clear.

  • Select a single row from a billion row table

    This is a fictitious scenario, how would you write a select statement on a table with a billion rows. It never returns anything,right? Somebody was suggesting a stored procedure.
    As an example : Assuming a Table with columns      Account(int), TransDate(DateTime), TransNum(int) and few other columns. I need a transaction that happened on 03-05-2014 8:15PM. Clustered index on Account. Non- clustered on TransDate.
    I was suggested to create a stored procedure, inside the SP you have 3 parameters: min_date, max_date, avg= min_date+max_date/2. You create a loop and feed the avg value to the max_date or min_date depending on where the row is. This is a suggestion
    that I am not clear my-self but wanted to see if you guys can help me develop this idea.
    Also please suggest how you would do it in your world. You guys could have much better ideas probably much simpler one's. Thanks in advance.
    svk

    I basically just need transaction for one particular datetime. Not any span. One of our senior developers suggested that a simple select statement takes for ever to return a single row from a billion rows and suggested a vague idea as above. 
    Either there is a suitable index on the column, and the SELECT will be fast.
    Or there is no index on the column, and in that case it will take quite some time to find the row. The only reason to loop is that you don't want to take out a table lock, but in that case you would do something like looping one account at a time. Looping
    over different time values will only mean that you will scan the table multiple times.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Selecting a single row from table control of standard transaction via repor

    Hi Experts,
    I have a requirement of selecting a single row from standard trasaction via ineractive report.
    For eg. for a given document number & item number, how can i select the specified item from transaction VA03.
    I am using call transaction to naviagate to the screen but unable to select the specified item.
    thanks in adavance for your Help.

    You mean selecting the item via BDC?
    Have you tried something like:
    perform bdc_field       using 'BDC_CURSOR'
                                  'VBAP-POSNR(01)'.
    perform bdc_field       using 'RV45A-VBAP_SELKZ(01)'
                                  'X'.
    or whatever your dynpro is to select the first row?

  • Deleting single row from Special Price for Business Partners

    Hi Experts,
    How would I go about about deleting a single row from Special Prices for Business Partners across all BPs when for most of my BPs this is the only special price they have.  I have tried using Copy Discounts function but once you are down to 0 rows the record has effectively gone from the table so there is nothing to copy. 
    Hopefully I won't have to go thorugh 5000 records and delete each one idividually.
    Thanks
    Jon

    Hi Jon,
    You may try a tool called B1TCH:
    /people/community.user/blog/2007/08/19/get-your-kicks-with-di-commander
    Thanks,
    Gordon

  • UPDATE single ROW from DATAGRID without refreshing the entire ItemsSource

    Hello there,
       I have a simple datagrid that has an ItemsSource of ObjectQuery<DbDataRecord>.
       Let's say I want to refresh a single row from the datagrid, (Because a specific item i know has been changed) without refreshing the entire ItemsSource because the source query is quite big.
    Any ideas?
    Thanks.
    -- Jorge_M_P

    Whilst you could raise property changed on every field in an item, that would of course mean implementing inotifypropertychanged on a wrapper object, then iterating all of those properties.
    An observablecollection implements the INotifyCollectionChanged interface.
    Amongst the possibilities for changes which that notifies are this one:
    https://msdn.microsoft.com/en-us/library/ms653207(v=vs.110).aspx
    Which notifies of a single item change.
    I usually wrap my entity framework objects.
    Sometimes I wrap all the properties so I can do change tracking in the viewmodel.
    This is a technique similar to the one I use in this sample:
    https://gallery.technet.microsoft.com/WPF-Highlight-Changed-a77976d4
    Which wraps plain classes - but the principle is the same.
    And
    I wrap the object and expose that, as I do in this:
    http://social.technet.microsoft.com/wiki/contents/articles/28209.wpf-entity-framework-mvvm-walk-through-1.aspx
    Note that because I wrap the same objects returned from EF, there is very little overhead in using an observable collection there.
    Hope that helps.
    Recent Technet articles:
    Property List Editing ;  
    Dynamic XAML

  • Importing single row from an exported dump of many tables

    Hi all,
    I have a requirement to import a single row from a exported dump which has collection of tables in it.
    i have used export of a single row and import of single row(from single row export dump), now i need to import a single row from a dump containing collection of tables...
    kindly help me out with this.

    971424 wrote:
    Hi all,
    I have a requirement to import a single row from a exported dump which has collection of tables in it.
    i have used export of a single row and import of single row(from single row export dump), now i need to import a single row from a dump containing collection of tables...
    kindly help me out with this.post command line that produced the dump file.
    How do I ask a question on the forums?
    SQL and PL/SQL FAQ

  • Delete single row from DBTAB

    Hi Experts,
    I want to delete a single row from DBTAB ( KLAH )
    WHERE KLAHKLART = '2'  and  KLAHCLINT = '241'.
    Please advice
    Karthik

    Hi ,
    Try this code  To delete single record from DB table- -
    DATA : t_klah LIKE TABLE OF klah,
           fs_klah LIKE klah.
    SELECT * FROM klah INTO TABLE t_klah
                   WHERE klart = '2' AND
                         clint = '241'.
    LOOP AT t_klah INTO fs_klah.
      DELETE klah FROM fs_klah .
      EXIT.
    ENDLOOP.
    Regards
    Pinaki

  • How To Access PAGE ITEM (single row) from HTML source

    Hi Guys,
    I have a page Item that return a string.
    I would like to show this string
    How To Access PAGE ITEM (single row) from HTML source?
    My desire final output is
    <marquee>:P1_PAGE_ITEM</marquee>
    Can please help me
    Thanks

    Hi,
    You can refer the page items in your page header as &itemname. For example, if I have page item P15_TEST, I will add the following in header:
    <marquee>
       &P15_TEST.
    </marquee>But make sure that you have a process before header to populate the value in your page item. Otherwise, there will be a null scrolling (which you can't see!) :)
    Regards,
    Zahid

  • Retrieving the entire row from ResultSet

    Hi All,
    I am using SQL database and wants to get the data from tables as rows instead of columns. Please let me know if any of you know how to retrieve the rows from table using ResultSet.
    Thanks.

    you would need a loop like this:
    for( int i = 0; i < resultset.getMetadata().getColumnCount(); i++ )
      System.out.print( resultSet.getXXX( i ) );
    }That will print out the row

  • ADF: How to get the attributes' values of one single row from a table?

    Currently I have a table with 3 attributes, suppose A,B and C respectively. And I've added an selectionListener to this table. That means when I select one single row of this table, I wish to get the respective value of A, B and C for that particular row. How do I achieve this?
    suppose the method is like:
    public void selectionRow(SelectionEvent se) {            //se is the mouse selection event
    .......??? //what should I do to get the values of A\B\C for one single row?
    Edited by: user12635428 on Mar 23, 2010 1:40 AM

    Hi
    Assuming you are using Jdev 11g.
    Try with this
    public void selectionRow(SelectionEvent se) {
    String val = getManagedBeanValue("bindings.AttributeName.inputValue");
    public static Object getManagedBeanValue(String beanName) {
    StringBuffer buff = new StringBuffer("#{");
    buff.append(beanName);
    buff.append("}");
    return resolveExpression(buff.toString());
    public static Object resolveExpression(String expression) {
    FacesContext facesContext = getFacesContext();
    Application app = facesContext.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    ValueExpression valueExp =
    elFactory.createValueExpression(elContext, expression,
    Object.class);
    return valueExp.getValue(elContext);
    Vikram

Maybe you are looking for