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

Similar Messages

  • 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.

  • 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

  • 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

  • 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?
    %

  • 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

  • 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

  • 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

  • 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.

  • Polling records from mulitiple table(61 Tables) using WCF-SQL adapter

    Hi,
    I would like get some suggestion from this forum. I've a scenario, in which I need to poll the records from multiple table(61) which are related and may have one to many relationship. what's the best way to poll the records from SQL table to BizTalk.
    Thanks in advance..
    Regards,
    Karthick

    Karthick,
    Write a SQL stored procedure with joins from your 61 tables (!!!) . Use WCF-SQL adapter to invoke the procedures.
    Following references shall help you:
    Executing Stored Procedures in SQL Server by Using BizTalk Server
    Performing Composite Operations on SQL Server by Using BizTalk Server
    Bing-Results: biztalk wcf sql
    adapter polling stored procedure
    I don’t know your exact requirement. Consider using SQL-SSIS for ETL process depending on your requirements. Anyway if your requirement really needs BizTalk, above suggest
    should solve your problem.
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • Query regarding the data type for fetcing records from multiple ODS tables

    hey guys;
    i have a query regarding the data type for fetcing records from multiple ODS tables.
    if i have 2 table with a same column name then in the datatype under parent row node i cant add 2 nodes with the same name.
    can any one help with some suggestion.

    Hi Mudit,
    One option would be to go as mentioned by Padamja , prefxing the table name to the column name or another would be to use the AS keyoword in your SQL statement.
    AS is used to rename the column name when data is being selected from your DB.
    So, the query  Select ename as empname from emptable will return the data with column name as empname.
    Regards,
    Bhavesh

  • Allow multiple records from this table to be displayed in the form is greyed out.

    I'm trying to add a second table to my main data source in an InfoPath 2010 form (database template), but the option to allow multiple records from this table to be displayed in the form is greyed out and I can't select it.
    Can someone please tell me how to correct this? I'm guessing that there might have to be something change in MS SQL because on other occasions I've have not encountered this problem when adding a second table.
    Any help would be greatly appreciated.
    Thanks.

    So I've found a work around, but I still don't know why I'm having the problem in the first place.
    I've been trying to relate the two tables by using the primary key in the parent table to a view of the child table that also includes primary key in the parent, e.g. the ORDER ID in the order table relating to the ORDER ID in the view of the order detail
    table. For whatever reason whenever I did that InfoPath prohibited the data source from returning multiple order details.
    My work around is to use views of both the order table and order details table that include the customer ID and to relate the two table in InfoPath using the customer ID. Now I get a data source that allows multiple order detail records. In order to get
    just the order details that I want that relate to a particular order, I use a rule that sets the order id in both the order and order details query data sets before executing the query (as opposed to just the order data set).
    Hope that's a clear explanation.

Maybe you are looking for

  • Creative Zen 8GB locking freezing problem

    )CMy creative zen is actibg up a bit. I locked it recentlly, to conserve the battery. However, it just froze there. My Player is not locked, but is still displaying the locked logo, without going to a black screen. Whenever I press a button, it doesn

  • User Exit for Foreign Trade

    Dear Experts, Am trying with User Exit (V50EPROP) EXIT_SAPLV50E_001 to create Default data of Transportation in Delivery Header Foreign Trade/Customs data. This Exit working for Foreign Countries but not working with in the same country. Eg: IN to IN

  • A/P Express Newbie question

    Hi. Considering getting an a/p express to stream music down to my family room. Question: it seems the speaker connections are pretty limited-- what sort of speakers do people use to stream wirelessly in a house. Is it a 1-speaker central speaker or t

  • .htaccess problems in DW MX2004 OSX 2.8 vs. DW Studio 8 on XP

    OKay guys, anyone have issues where they can not get the server to accept the .htaccess file while using MX 2004 on a Mac? On my old skool G3 at home, It looks like DW has checked-in or put the .htaccess file but indeed it isn't there because- DUH! t

  • Importing bc4j from jar in project

    Hi, since we have a complex application, we want to group application modules logically into smaller modules (submodules), which must be combined to yield more complex modules. Every submodule lives in its own project, so reusing a submodule in a mor