Using ResultSet to read records from multiple tables

Im using a ResultSet object to read records from tables.
I have a database with 5 tables. Initially, I got it to work fine with one of those tables. What Im exactly trying to do is check if there is a record in a table which matches a given string, and if it does, display some text on some JTextFields. I got that to work fine with one table.
Problem is, how do I get it to work with all 5 tables at the same time?
i.e. instead of searching through one table, I want it to look through all 5 tables and look for the matches.
Any help greatly appreciated.
Thanks

After the first interaction with the first table, I
used a stmt.getMoreResults() followed by instructions
to get data from the second table, and so on.
Worked fine.Sounds remarkably inefficient. (Potential for lots of network traffic.)
is this another way of doing it?Sounds more like a document search type of thing than a database query. What about Lucene? Could it help here?
%

Similar Messages

  • Records from multiple tables

    Hi,
    I have a method that has to access records from multiple tables and store them all in a file. It's something like this:
    switch (tableId){
    case 'A' : query="SELECT * FROM TABLE_A
    WHERE ID = '" + tempId + "'";
    ResultSet rs = stmt.executeQuery (query);
    rs.close();
    break;
    case 'B' : query="SELECT * FROM TABLE_B
    WHERE ID = '" + tempId + "'";
    rs = stmt.executeQuery (query);
    rs.close();
    break;
    case 'C' : query="SELECT * FROM TABLE_C
    WHERE ID = '" + tempId + "'";
    rs = stmt.executeQuery (query);
    rs.close();
    break;
    My problem is that I get an "Invalid cursor" error the second time I enter the loop. I've been reading up on cursors but I still don't know what to do. Can I use ResultSet to return multiple rows from multiple tables? If not, what can I use? Please help!
    Thanks in advance.

    remove the "rs.close()" from the switch statement. use "rs.close()" after your loop ends.
    prem

  • Delete records from multiple table

    Hi,
    I need to delete records from multiple tables using a single delete statement. Is it possible ? If so please let me know the procedure.
    Kindly Help.
    Thanks,
    Alexander.

    Hi Tim,
    Syntax of DELETE statement does not allow for multiple tables to be specified in this way. Infact, none of the DMLs allow you to specify table names like this.
    Technically, there are other ways of deleting from multiple tables with one statement.
    1. "Use a trigger":
    What was probably meant by this is that you have a driving-table on which you create a on-delete trigger. In this trigger, you write the logic for deleting from other tables that you want to delete from.
    This does mean a one-time effort of writing the trigger. But the actual DML operation of deleting from all the tables would be simply triggered by a delete on driving-table.
    2. Dynamic SQL:
    Write a PL/SQL code to open a cursor with table-names from which you want the data to be deleted from. In the cursor-for loop, write a dynamic SQL using the table-name to delete from that table.
    3. Using Foreign-Key constraint with Cascade-Delete:
    This I feel is a more 'cleaner' way of doing this.
    Having to delete data from multiple tables means that there is some kind of parent-child relationship between your tables. These relationships can be implemented in database using foreign-key constraints. While creating foreign-key constraint give the 'on delete cascade' clause to ensure that whenever data is deleted from parent-table, its dependent data is deleted from child-table.
    Using foreign-key constraint you can create a heirarchy of parent-child relationships and still your DELETE would be simple as you would only have to delete from parent-table.
    IMPORTANT: Implementing foreign-key constraints would also impact other DML operations that you should keep in mind.

  • How to read records from Relationship table using ABAP API's

    Hi All,
    I need to retrieve the records from Relationship table. In Java API's I came to know there is an option to retrieve this. I could not find anything in ABAP API's. Is there any option in ABAP API's to do this.
    Please Suggest.
    Thank You,
    Gajendra.

    Hi Gajendra,
    You can mainly read records from MDM (in a DDIC structure) using ABAP API's using the following function modules/methods:
    1. RETRIEVE: This is used to generically retrieve records from tables. Attributes and Values can also be retrieved.
    2. RETRIEVE SIMPLE: Retrieve records from MDM in a simple way.( simple data types).
    3. RETRIEVE CHECKOUT: Retrieves all checked out ID's.
    4. RETRIEVE ATTRIBUTES: Retrieves attribute(s) from a Taxanomy table.
    You will find all these methods in the following interface
    Interface : IF_MDM_CORE_SERVICES
    Hope it helps.
    *Please reward points if found useful.
    Thanks and Regards
    Nitin Jain

  • Need assistance searching records from multiple tables - Please Help!

    Hi, I've been trying to solve this problem for several weeks now, and I have exhausted all of my knowledge and experience.  I need help, and I hope someone here can give me some direction.
    I am using VB 2008, and the CR that comes bundled with VS 2008 Pro.  My database is a SQL Server 2005 CE v3.5 (a *.sdf file).  I am connecting to the database through a dataset, and I am displaying the report in a CrystalReportViewer.
    My dataset consistes of two tables:
    1) tblCustomers which has a primary key "CustID", and contains only customer contact and personal information. 
    2) tblDateVisited which has a primary key of "VisitID", but it also has a column titled "CustID". Basically, every time a customer visits the business, details of that visit are recorded in tblDateVisited, and that record is associated with the customer by their CustID.
    Here's what I'm trying to accomplish:  I want to be able to display only Customer records when the customer has visited and that visit matches certain criteria.  Right now, I am trying to match visits from the "tblVisitDate.PlayerType" column.  If the customer has ever had a visit where they matched a particular player type, I want to see those customer records.
    I don't know what I'm doing wrong, though.  I can search a dataset if I am only querying one table and pulling records from that table.  However, whenever I try to add a second table and perform queries on that table to get records from the first table, I can't return any records. 
    If it helps, I am trying to use one CrystalReportViewer to display multiple reports (user choice) and here's how I'm loading the report into the viewer:
    Me.tblCustomersTableAdapter.Fill(Me.dsPlayerTypeReports.tblCustomers)
    Me.tblDateVisitedTableAdapter.Fill(Me.dsPlayerTypeReports.tblDateVisited)
    Me.ReportFile.SetDataSource(dsPlayerTypeReports.Tables(1))
    I am suspicious that my problem is in the Tables(1) method.  It confuses me that I can only assign one table as a datasource when I obviously need access to two tables to make this selection work. 
    Whatever the case, I'm at the end of my rope with this one.  I'm not prone to giving up, but I'm at a dead end currently. 
    Any attempt to assist me with this will be greatly appreciated, successful or not.
    Thanks in advance!
    -Will

    No, I am connected via ADO.NET.  I don't think SQL CE can connect through ODBC (or if it can, I haven't been able to figure out how, yet).  So this isn't a stored procedure.
    When I examine the link, I can only choose an Inner Join or a Left Outer Join.  Right Outer and Full Outer are not available.  Could this be a problem with the dataset I'm using?
    Could you explain what you mean by display all of the records and then choose the selection criteria?

  • Sender JDBC Adapter : Fetch records from multiple tables

    Hi Friends,
    I am using sender JDBC adapter to select few records from DB2 database table.
    This scenario is working fine.
    Now my requirement is to fetch records from 3 tables. These table are independent to each other. There is no primary key or foreign key.
    Please let me know how to write the sql in sender JDBC adapter to fetch records from these 3 tables.
    Thanks,
    Sandeep Maurya

    hi sandeep...
    if the tables are completely independent and do not share any primary / foreign key relation ship...
    why dont u think towards creating a seperate interface for each of them..
    or if u still want to select from multiple table at once..the best way would be to write a stored procedure on the sender side which do all the fetching n processing and pass the final resultset to PI
    or u can think towards fetching the data from 1 table and then in UDF do lookup from other tables..which again is tricky and performace intensive

  • Extracting Records from multiple tables

    hi
    I have to extract almost 1 lack  records from 3 tables.
    Please help me in ABAP CODE.
    PLease it is very urgent.

    Which tables are they ?  Refer to link below for more hints abt performance.
    Re: select query - optimization

  • Records from multiple table in Forms using Structure

    Hi all,
    I thought of bringing records from more than one table to smart forms.I have done the same by using two internal tables but not using with globally declared structure.Is it like this:
    1.Create the global structure
    2.In driver program create a internal table
    3.Pull the data using select statement
    4.Pass the internal table to smartforms-> Here I dont understand how.Usually In smartforms we declare internal tables of table type like 'itable type zgkmaster'
    How to pass the internal table we created using structure to smartforms?
    Thanks

    Hi Gopi,
    the procedure u r telling is correct.
    create the structure(ex:zstruc) in se11 as the structure of the internal table.
    *popluate the data into internal table.
    *in smartform, u declare the internal table as that structure i.e itab type zstruc.
    i.e in smartforms when u declare internal table, u r telling that ur internal table having the structure similar to the structure ZSTRUC.
    In smartforms u can declare the table type using either ...type <db table> or ... type <structure>.
    san

  • Read record from parent table

    Hello,
    I have a table which is linked (using FK) with a number of other tables which are linked with other tables, etc. (like a tree). Using ADO.NET EF provider within ODAC 11.2.0.3 Release 5 I am trying to get a record from the root table. I coded a test using MSTest and when I do "myContext.MyTable.Where(...).FirstOrDefault();" VS2010 stops the debugging process after a while - no exception is caught in code but I get an error in Test results window: "The test adapter 'UnitTestAdapter' threw an exception while running test '<my test>'. Exception has been thrown by the target of an invocation.
    Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
    In the Debug window/view I get this:
    A first chance exception of type 'System.AccessViolationException' occurred in Oracle.DataAccess.dll
    A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
    A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter.dll
    Step into: Stepping over method without symbols 'Microsoft.VisualStudio.TestTools.Agent.AgentExecution.CallAdapterRunMethod'
    W, 7380, 13, 2012/11/09, 23:33:29.803, QTAgent32.exe, AgentExecution: Exception while calling TestAdapter.Run: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    at Oracle.DataAccess.Client.OpsDac.Read(IntPtr opsConCtx, IntPtr opsErrCtx, IntPtr opsSqlCtx, IntPtr& opsDacCtx, OpoSqlValCtx* pOpoSqlValCtx, OpoMetValCtx* pOpoMetValCtx, OpoDacValCtx* pOpoDacValCtx)
    at Oracle.DataAccess.Client.OracleDataReader.Read()
    at System.Data.Common.Internal.Materialization.Shaper`1.StoreRead()
    at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
    at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1[TResult](IEnumerable`1 sequence)
    at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
    at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
    at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
    at <my code stack>
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
    at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.DefaultTestMethodInvoke(Object[] args)
    at Microsoft.VisualStudio.TestTools.TestTypes.Unit.DefaultTestMethodDecorator.Invoke(Object[] args)
    at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.RunTestMethod()
    at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.ExecuteTest()
    at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.Execute(UnitTestResult result)
    at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestRunner.ExecuteSingleTest(UnitTestExecuter executer, UnitTestElement test, ITestContext testContext, UnitTestAdapterContext userContext, Boolean isLoadTest)
    at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestRunner.Run(UnitTestElement test, ITestContext testContext, Boolean isLoadTest, Boolean useMultipleCpus)
    at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestRunner.Run(UnitTestElement test, ITestContext testContext, Boolean isLoadTest, Boolean useMultipleCpus)
    at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter.Run(ITestElement testElement, ITestContext testContext, Boolean isLoadTest)
    at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter.Run(ITestElement testElement, ITestContext testContext)
    at Microsoft.VisualStudio.TestTools.Agent.AgentExecution.CallAdapterRunMethod(Object obj)
    The thread 'Agent: adapter run thread for test '<my test>' with id '0779674e-2258-44d4-adfe-65302abbe50f'' (0x13e0) has exited with code 0 (0x0).
    W, 7380, 30, 2012/11/09, 23:33:29.869, QTAgent32.exe, Performance warning: m_test should be null when TestResult is serialized. Please find the offending code and correct it.
    E, 7380, 30, 2012/11/09, 23:33:29.879, QTAgent32.exe, AgentExecution: Received adapter message during test shutdown: run id {94200779-4759-4b4a-819c-61c55d39acbc}, test '<my test>' with id 0779674e-2258-44d4-adfe-65302abbe50f: MessageKind: Result, Outcome: Error
    The thread 'ExecutionUtilities.InvokeWithTimeout helper thread 'Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter.AbortTestRun'' (0x1f98) has exited with code 0 (0x0).
    The thread 'Agent: state execution thread for test '<my test>' with id '0779674e-2258-44d4-adfe-65302abbe50f'' (0x2688) has exited with code 0 (0x0).
    The thread 'Agent: test queue thread' (0x1c58) has exited with code 0 (0x0).
    A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
    A first chance exception of type 'System.Threading.ThreadAbortException' occurred in Oracle.DataAccess.dll
    A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
    The thread '<No Name>' (0x24c0) has exited with code 0 (0x0).
    A first chance exception of type 'System.Threading.ThreadAbortException' occurred in System.Data.Entity.dll
    A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
    A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
    The thread '<No Name>' (0x2410) has exited with code 0 (0x0).
    The thread '<No Name>' (0x2520) has exited with code 0 (0x0).
    E, 7380, 6, 2012/11/09, 23:35:17.912, QTAgent32.exe, AgentObject: Cleanup: Timeout reached in cleaning up the agent.
    E, 7380, 6, 2012/11/09, 23:35:22.918, QTAgent32.exe, AgentObject: Cleanup: Timeout reached in cleaning up the agent.
    The program '[7380] QTAgent32.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
    Any idea is appreciated!
    Thanks
    Edited by: 917334 on Nov 10, 2012 12:17 AM
    The equivalent where statement works well in classic ADO.NET.

    Hello
    Use the below function module
    RV_ORDER_FLOW_INFORMATION pass the type as C and pass the number.You will get all the flow.
    SELECT VBELN KNUMV BUKRS KUNRG REGIO NETWR FKSTO FKDAT FKART  INTO CORRESPONDING FIELDS OF TABLE T_VBRK  FROM VBRK WHERE BUKRS IN P_BUKRS AND FKDAT IN P_FKDAT AND VKORG IN P_VKORG AND REGIO = '07'
        ORDER BY VBELN KNUMV.
    SORT T_VBRK BY vbeln.
      LOOP AT T_VBRK.
        IF  T_VBRK-FKART = 'F2' OR T_VBRK-FKART = 'YF2' OR T_VBRK-FKART = 'ZF2' OR
            T_VBRK-FKART = 'ZG2' OR T_VBRK-FKART = 'ZL2' OR T_VBRK-FKART = 'YG2' OR T_VBRK-FKART = 'YL2' .
          IF T_VBRK-FKSTO IS INITIAL.
    i_vbco6-vbeln = t_vbrk-vbeln.
    CALL FUNCTION 'RV_ORDER_FLOW_INFORMATION'
      EXPORTING
      AUFBEREITUNG        = '2'
      BELEGTYP            = ' '
        COMWA               = i_vbco6
      NACHFOLGER          = 'X'
      N_STUFEN            = '50'
      VORGAENGER          = 'X'
      V_STUFEN            = '50'
    IMPORTING
      BELEGTYP_BACK       =
      TABLES
        VBFA_TAB            = t_vbfa
    EXCEPTIONS
       NO_VBFA             = 1
       NO_VBUK_FOUND       = 2
       OTHERS              = 3
    endif.
    ENDIF.
    endloop.
    loop at t_vbfa.
      if t_vbfa-vbtyp_V = 'C' OR t_vbfa-vbtyp_V = 'K' OR t_vbfa-vbtyp_V = 'L' OR t_vbfa-vbtyp_V = 'E' .
    *clear t_vbfa.
    SELECT VBELN BSTNK BSTDK FROM VBAK INTO CORRESPONDING FIELDS OF TABLE T_VBAK FOR ALL ENTRIES IN T_VBFA WHERE VBELN = T_VBFA-VBELV .
    endif.
      ENDLOOP.
    In case of any more help is required do let me know
    Regards,
    Nabheet Madan

  • Reading data from multiple tables on Apex

    Hi All,
    My apologies if the below question has been answered already, just that I could not find the relevant discussion.
    I have an interactive report that I would like to use to display data from 2 tables:
    Table 1 has about 10 columns but I just want to display 3 of those columns, field1, field2 & field3.
    Table 2 has about 5 columns and I only want to display 2 of these columns(Column1 & Column2) on the same report with the above columns from table 1.
    I need my report to look like this: field1  field2 field3 Column1 Column2
                                                    from table1, table2
    I tried the above example and it seems not to be working, may I please get some assistance on how to achieve this.
    Thanks in advance.

    Hi There,
    Thanks for your response, I've actually found and answer the question.
    I wanted to display data from 2 separate tables(views) that did not have joints, and so hence I could not join them with a join condition.
    What I did was to created a dummy field on both tables with similar values and joined the tables using those dummy fields and it works perfect.
    Thanks.

  • Problem selecting records from multiple tables

    Good day
    I am writing  a report showing actual vs budget amount per period.  The actual amounts are in one table and the budget amount are in another table.  In this example it is for vehicle sales.  The problem is that in the budget table, there are no records for a particular make if it was not budgeted to make a sale.  If I try to get the records using the select expert it matches the key in actual table with key in budget table and retrieve.  What happens then is that the records in the actual table get excluded if there was not a record for it in the budget table.  How do I then do this selection, i.e. if there is a record in the budget table, then retrieve, otherwise make the budget amount 0?
    Thanks
    Wilhelm

    This is always difficult the best way is to use a command and union the two sets of data.
    First part uses a left outer join from Actual to Budget and brings back all actual data with and without a budget.
    Second parts brings back data from budegt where nothing exists in actual
    select (field list) from
    Actual a
    left outer join Budget b on a.field = b.field
    where (any other filter condition)
    union all
    select (field list) from
    budget b
    left outer join actual a on b.field = a.field and a.field is null
    where (any other filter condition)
    You can get the first query from your current report and the modify to build the second unioned query.
    Ian

  • Search a record from Multiple Tables

    Is there a pl/sql command or way that searches for a specific record (text, number) in multiple tables? Given that you don't know the column you are searching from.

    There is no built in method, but you can roll your own.
    I posted one way Re: How to find out a tablename
    HTH
    John

  • How to Concatenate Multiple Column Records from multiple tables

    my question is
    there are three tables like A,B,C
    i want the data from these tables with the help of relation
    select a.simno,b.item_code,c.desc
    from A a,B b,C c
    WHERE a.ms=b.ms and
    b.item_code=c.item_code
    and a.ms=c.ms
    the output for this query which i am getting is
    simno item_code desc
    1 i1 abc
    1 i2 def
    1 i3 xyz
    2 i4 gtr
    2 i5 poi
    but i want the output in this
    simno details
    1 abc#def#xyz
    2 gtr#poi
    and so on
    if it dispayes the output inthis manner i can save as ".csv" file

    Hi,
    There are different Solutions you can achieve
    Refer to Asktom : http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2196162600402
    SQL> create table test(simno number, itemcode varchar2(5), desc1 char(5))
    Table created.
    SQL> insert into test(simno,itemcode,desc1) values (1 ,'i1' ,'abc');
    1 row created.
    SQL> insert into test(simno,itemcode,desc1) values (1 ,'i2' ,'def') ;
    1 row created.
    SQL> insert into test(simno,itemcode,desc1) values (1 ,'i3' ,'xyz') ;
    1 row created.
    SQL> insert into test(simno,itemcode,desc1) values (2 ,'i4' ,'gtr');
    1 row created.
    SQL> insert into test(simno,itemcode,desc1) values (2 ,'i5' ,'poi');
    1 row created.
    SQL> select simno,wmsys.wm_concat(desc1) CONCAT
      2  from test
      3  group by simno;
         SIMNO
    CONCAT
             1
    abc  ,def  ,xyz
             2
    gtr  ,poi- Pavan Kumar N

  • Choosing most recent records from multiple tables?

    Let's say that you have two tables; one contains news
    articles with the fields TITLE, ARTICLE, and a timestamp DATE and
    the other contains different news articles with the fields TITLE,
    DESCRIPTION, and a timestamp DATEPOSTED.
    How would you go about selecting the (let's say) five most
    recent articles with the corresponding fields? I'm relatively new
    to CF but even the experienced guy in our office can't figure it
    out. The following code is what we were working with -- which
    doesn't quite work the way it should anyway -- but I'm thinking
    there
    must be an easier (or at least less convoluted) way.

    Thank you so much! Azadi hit the nail on the head; I hadn't
    known the terms to look for so Google hadn't been any help, but
    UNION was just the trick for this MySQL query. I had to add a field
    to each table in order to tell the link which page to go to since
    there's a different one depending on which table the record came
    from, but here's the code that works (just in case anyone else does
    a search for this problem):

  • Delete records from multiple tables and add delay in execution

    Dear All,
    My Database is Oracle 11gR2 on Linux.
    I have to schedule delete in 5 tables. For this i will write a procedure with delete queries and schedule the procedure to run daily in night.
    I want to give delay in the execution of delete queries within procedure? How can i add this functionality within a procedure?
    I don't want to lock the tables as other queries may be accessing the same table meanwhile.
    Looking for your help.
    Regards,
    Imran

    Duplicate thread - see https://forums.oracle.com/thread/2553380 for answer.

Maybe you are looking for