Preparedstatement with two tables

I try to use "preparedstatement" to insert two tables. Is there any posibility to control the constraint of the two tables? Assume that the two tables are master detail. Commit them both or rollback them both... An example would be very helpful.

Something like that: if the preparedstatement2 throws an exception then I should rollback the preparedstatement1.
StringBuffer stringbuffer = new StringBuffer();
stringbuffer.append("insert into T_ABC");
stringbuffer.append("(a,b,c)");
stringbuffer.append(" VALUES(?, ?, ?);
StringBuffer stringbuffer2 = new StringBuffer();
stringbuffer2.append("insert into T_DEF");
stringbuffer2.append("(d,e,f,g)");
stringbuffer2.append(" VALUES(?, ?, ?, ?);
preparedstatement1 = dc.prepareStatement(stringbuffer.toString());
preparedstatement2 = dc.prepareStatement(stringbuffer2.toString());
preparedstatement1.setLong(1, 0);
preparedstatement1.setLong(2, 0);
try {
preparedstatement1.executeUpdate();
preparedstatement2.executeUpdate();
} catch {
//control
}

Similar Messages

  • For All Entries with two tables

    Hi All,
             Can we use FOR ALL ENTRIES with two tables. for example
    SELECT * FROM MKPF INTO TABLE T_MKPF
             WHERE BUDAT IN S_BUDAT.
    SELECT * FROM MARA INTO TABLE T_MARA
             WHERE MTART IN S_MTART AND
                            MAKTL IN S_MAKTL.
    SELECT * FROM MSEG INTO TABLE T_MSEG
           FOR ALL ENTRIES IN  "T_MKPF AND T_MARA"
                  WHERE MBLNR EQ T_MKPF-MBLNR AND
                                 MATNR EQ T_MARA-MATNR.
    can we do it like this or any other way to do this plz tell. I waitting for your responce.
    Thanks
    Jitendra

    Hi,
    u cannot do like this....chek some documentation on it..
    1. duplicate rows are automatically removed
    2. if the itab used in the clause is empty , all the rows in the source table will be selected .
    3. performance degradation when using the clause on big tables.
    Say for example you have the following abap code:
    Select * from mara
    For all entries in itab
    Where matnr = itab-matnr.
    If the actual source of the material list (represented here by itab) is actually another database table, like:
    select matnr from mseg
    into corresponding fields of table itab
    where ….
    Then you could have used one sql statement that joins both tables.
    Select t1.*
    From mara t1, mseg t2
    Where t1.matnr = t2.matnr
    And T2…..
    So what are the drawbacks of using the "for all entires" instead of a join ?
    At run time , in order to fulfill the "for all entries " request, the abap engine will generate several sql statements (for detailed information on this refer to note 48230). Regardless of which method the engine uses (union all, "or" or "in" predicates) If the itab is bigger then a few records, the abap engine will break the itab into parts, and rerun an sql statement several times in a loop. This rerun of the same sql statement , each time with different host values, is a source of resource waste because it may lead to re-reading of data pages.
    returing to the above example , lets say that our itab contains 500 records and that the abap engine will be forced to run the following sql statement 50 times with a list of 10 values each time.
    Select * from mara
    Where matnr in ( ...)
    Db2 will be able to perform this sql statement cheaply all 50 times, using one of sap standard indexes that contain the matnr column. But in actuality, if you consider the wider picture (all 50 executions of the statement), you will see that some of the data pages, especially the root and middle-tire index pages have been re-read each execution.
    Even though db2 has mechanisms like buffer pools and sequential detection to try to minimize the i/o cost of such cases, those mechanisms can only minimize the actual i/o operations , not the cpu cost of re-reading them once they are in memory. Had you coded the join, db2 would have known that you actually need 500 rows from mara, it would have been able to use other access methods, and potentially consume less getpages i/o and cpu.
    In other words , when you use the "for all entries " clause instead of coding a join , you are depriving the database of important information needed to select the best access path for your application. Moreover, you are depriving your DBA of the same vital information. When the DBA monitors & tunes the system, he (or she) is less likely to recognize this kind of resource waste. The DBA will see a simple statement that uses an index , he is less likely to realize that this statement is executed in a loop unnecessarily.
    Beore using the "for all entries" clause and to evaluate the use of database views as a means to:
    a. simplify sql
    b. simplify abap code
    c. get around open sql limitations.
    check the links
    http://www.thespot4sap.com/articles/SAPABAPPerformanceTuning_ForAllEntries.asp
    The specified item was not found.
    Regards,
    Nagaraj

  • How to deal with two tables in the Data Base

    Hi Experts,
    IF WE WANT TO GET THE DATA FROM THE TWO TABLES, WHAT QUERY SQL STATEMNET SHOULD HAVE TO WRITE AND ANY CONFIGURATION CHANGES NEED TO BE DONE AND WHAT SETTINGS NEED TO BE DONE IN THE ESR .
    PLEASE EXPLAIN ME ON THIS .
    THANKS IN ADVANCE.
    RAM

    If you are using the same database and referencing two tables then you dont need special configuration for it. You use single jdbc adapter. In ESR you create two statment structure one for each table. This is one option. The second option is use join statment and write query and in this case one statment data structure.
    Please go through the help sap link for the jdbc document structure.
    http://help.sap.com/SAPHELP_NW04s/helpdata/EN/2e/96fd3f2d14e869e10000000a155106/content.htm
    The second option can be done using the below structure.
    <StatementName>
    <anyName action=u201D SQL_QUERYu201D >
    <access>SQL-String with optional placeholder(s)</access>
    <key>
      <placeholder1>value1</placeholder1>
      <placeholder2>value2<placeholder2>
    </key>
    </anyName > 
    </StatementName>

  • FOR ALL ENTRIES IN with two tables

    Hi Guy's,
    I have two int. tables, gt_likp, gt_lips.
    I need to use "FOR ALL ENTRIES IN" with this two tables.
      SELECT matnr
             vkorg
             vtweg
             ypcogsl
        FROM mvke
        INTO TABLE gt_mvke
    <b>    "FOR ALL ENTRIES IN gt_likp gt_lips"</b>
        WHERE matnr = gwa_liefpos_tab-matnr
        AND vkorg = gt_likp-vkorg
        AND vtweg = gt_lips-vtweg.
    How to do this?
    Please Help.
    Thanks in Advance.

    Hi,
    Fill gt_likp-vkorg values in a range(r_vkorg). Use gt_lips in FOR ALL ENTRIES.
    Basically you can use only 1 internal table with FOR ALL ENTRIES statement.
    SELECT matnr
    vkorg
    vtweg
    ypcogsl
    FROM mvke
    INTO TABLE gt_mvke
    FOR ALL ENTRIES IN gt_lips
    WHERE matnr = gwa_liefpos_tab-matnr
    AND       vkorg in r_vkorg
    AND       vtweg = gt_lips-vtweg.
    - SRao

  • Please help with two tables...

    I've created form based on two tables - two blocks with relationship. One table have fields ID and DESCRIPTION and there is LOV based on it. LOV returns value to textbox. I want that user see in textbox value DESCRIPTION, but when user save changes to main table there is update on ID field. How can I do that?
    PS Sorry my english is not perfect.

    see this link , i guess you are looking for same thing
    Copying value from updated block to newly created bolck

  • Trouble with two tables and persistence

    Hi all,
    I would need your opinion on this:
    I have two tables:
    Table User (UID(PK), Uname, Pword)
    Table Choice (CID(PK), UID(FK), Cname, Cparameter1, Cparameter2)
    I have tried to put both together into one entity as described in: http://en.wikibooks.org/wiki/Java_Persistence/Tables#Example_mapping_annotations_for_an_entity_with_multiple_tables
    However, the trouble is that it doesn't work as I have hoped. I am unable to insert data into the user table alone, because it complains about missing entries for CID, Cname, etc...). I thought I would be able to query them independently, as 1 user can have many Choices.
    Any suggestions how to tackle this problem?
    Thank you.

    Ahh, I think I have figured out part of it but it isn't working yet. I created a view of the trk_user table. Now I need help with the code, I am trying to incorporate it here:
    SELECT webb.TRK_CALLS_VIEW.ID, webb.TRK_CALLS_VIEW.USER_, webb.TRK_CALLS_VIEW.ASSIGNED_TO, webb.TRK_CALLS_VIEW.PROBLEM, webb.TRK_CALLS_VIEW.SOLUTION, webb.TRK_CALLS_VIEW.STATUS, webb.TRK_USER_VIEW.lname, webb.TRK_USER_VIEW.fname
    FROM webb.TRK_CALLS_VIEW, webb.TRK_USER_VIEW
    WHERE
    ( STATUS = 'Open' and :P2_REPORT_SEARCH is null )
    or
    ( regexp_like( USER_ || '#' || ASSIGNED_TO || '#' || PROBLEM || '#' ||
    SOLUTION || '#' || STATUS, :P2_REPORT_SEARCH, 'i' ) )
    Can someone help me in the right direction

  • IDoc to JDBC with two tables

    Hi guys,
    I'm doing an interface IDoc to JDBC. With one IDoc (ORDERS) I have to perform two INSERT's in two different tables. I already read the SAP Help and there I saw that it is possible to do several statements in one or more tables! But, strangely, surfing on SDN forum I found some threads regarding the same scenario and the solution used is to use a multi mapping 1x2 and two JDBC adapter, one per table.
    Does anyone know if it is possible and which is the best approach for this scenario?
    Thanks in advance,
    Ricardo.

    Hi,
    As above bhavesh said is the correct,We can acheive this using two statement level tags.no need to use two comm channels.Under first statement level tag u can assign your sirst table name and under second statement level tag u can assign second table name.Finnaly source data is moved to two different tables in database system.
    Thanks
    KP..!

  • Working with two tables in Request!!! Any alternative solution?

    Hi All,
    I am stuck with a requirement, it is as follows,
    I have one table say Table1 with DATE,CYRRENCY and AMOUNT . User will select a date, we need to get all records greater than date selected by user from Table 1.
    Now I need to get exchang rate and currency for the date selected by user from other table say Table2 which has got details DATE, CURRENCY and EXCHANAGE RATE.
    Next step will be, Amount*Exchange Rate will be shown Currency wise.
    we need to do this calculation at run time based on date selected by user.
    I tried to do this in many ways like union query, changing data model at ETL layer etc. But not able to achieve.
    Your valuable suggestions would help me.
    Thanks.

    Thanks for the response, i am getting some idea, need bit clarification.
    For example, In table2 i will have records like below for the selected date:
    Currency Exchange Rate
    USD 47
    EUR 59
    In output of Table 1 i will take records greater than slected date range, that will have again currency and amount
    Currency Amount
    USD 2000
    EUR 1000
    USD 5000
    INR 1500
    we would need to match currency and take Amount * Exchange rate....
    Can this be achieved with presentation variable?
    Please help.

  • Report generation with two tables having no join

    Hi, 
           I would like to know if i can generate a report to view data from purchase and sales tables at one time even if they are not directly linked.
    Regards,
    Bhavna

    hi jain,
    You can use Union All to combine sql queries of sales and
    purchase tables.
    Jeyakanthan.

  • Calling a web service with two tables

    Hello all,
         I am having a problem calling a web service in VC which has data of the format order and orderitems.
    that is I have a record of information a recordset is part of that information. Please point to any blogs or any info available on SDN.
       I appreciate all your help
    Thank You
    Shekar

    Hi,
    Please check the below links.
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/vc71/webServiceDestination.
    https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/4679. [original link is broken] [original link is broken] [original link is broken]
    Govindu

  • Outer join two tables with query search record attached to both tables

    When I create a query with two tables that have query search records attached with outer join, PS seems to do a natural join (cartesian). We are on PT8.48.
    Is there a workaround for this issue. I do not want to remove query search record on either of the tables.
    I am trying to create an Emergency contact report. I am using two tables PS_EMPLOYEES and PS_EMERGENCY_CNTCT. Here is the sql PeopleSoft query generated when I did Left outer Join.
    Query SQL:
    SELECT A.EMPLID, A.NAME, A.ADDRESS1, A.CITY, B.PRIMARY_CONTACT, B.ADDRESS1, B.CITY, B.STATE, B.POSTAL, B.RELATIONSHIP, A.DEPTID, A.JOBCODE, A.COMPANY, A.EMPL_TYPE
    FROM (PS_EMPLOYEES A LEFT OUTER JOIN PS_EMERGENCY_CNTCT B ON A.EMPLID = B.EMPLID ), PS_EMPLMT_SRCH_QRY A1, PS_PERS_SRCH_QRY B1
    WHERE A.EMPLID = A1.EMPLID
    AND A.EMPL_RCD = A1.EMPL_RCD
    AND A1.OPRID = 'SREESR'
    AND (B.EMPLID = B1.EMPLID OR B.EMPLID IS NULL )
    AND B1.OPRID = 'PS'
    Appreciate any help.

    I think there are fixes for this issue in later tools releases (Report ID 1544345000). I'm not sure about 8.48, but you might try the workaround documented in
    E-QR: Left Outer Joins with Security Records are returning unexpected results [ID 651252.1]
    on Oracle Support.
    Regards,
    Bob

  • DataType conflict in the R/3 when joining two tables

    Hi Experts,
    I have created a view with two table in the R/3 side by joining two common fields,but one of the field is getting error with different data type, so could any one suggest me how to resolve this issue without changing type.
    Thanks,
    Venugopal

    Hi
    Actually I have to pull one of the  field from one table and place in other table and create a generic data source on it,Can any one suggest me with any solution or exists to solve this issue.
    Thanks,
    Venugopal

  • How to copy the value of two tables into a view.

    Hi Experts ,
    I have a requirement in which i have been provided with two tables(T1,T2) of same table structure ,i need to copy their entries into a table view with the same structure as the two tables(T1,T2) .
    suppose T1 has entries name age T2 has entries
    A 20 D 40
    B 30 E 46
    C 40
    the view should have all the entries,duplicate values no issues ...
    Could you please suggest how can i do that ?
    Thanks and Regards
    Debashis

    if table have same structure then you can use
    select * from t1
    union all
    select * from t2

  • CSV export from SSRS gives a line break if there are two tables

    I have a report with two tables. There is no gap between in the reports. The report looks good when I run it, but when I export the report to CSV, there is an extra line between the two tables. Can somebody help me fix this issue.
    Thanks in advance.
     

    Hi Bindu,
    If I understand correctly, you have two tables in the report. When you export to CSV, it has an extra blank line between these two tables. I have create a simple report in my test environment, I can reproduce the same issue.
    Based on your description, you want to splice these two tables with no gap in the report. I order to meet your requirement, we can use subreport to work around the issue. We can insert two aubreports in one table. Then, display these two tables in these
    two subreports.
    Reference: Subreports
    Alternatively, we can display these data in one table to work around the issue. If possible, you can post your sample data, we can to do further analysis. If these columns is from two datasets, please check if there has same fields. If so, we can use
    Lookup function to display two datasets data in one tablix.
    Regards,
    Alisa Tang
    If you have any feedback on our support, please click
    here.
    Alisa Tang
    TechNet Community Support

  • Displaying two tables in a region

    Hi.,
    I am using jdev11.5
    My Usecase:
    => I had created a ADF TreeTable with two tables Hd and Ln.
    => If the user clicks post button entier table should be replaced with some other attributes of the same table
    If i am not clear please check the link given below
    http://www.4shared.com/photo/3_LBY6lH/2001.html
    Pls provide me any information regarding this use case

    you can use dynamic table.. feature..
    http://jobinesh.blogspot.com/2010/06/model-driven-approach-for-building.html
    http://blogs.oracle.com/shay/entry/adf_faces_dynamic_tags_-fora

Maybe you are looking for

  • Export CLOBs with text into their own file?

    I have a CLOB column in a table. I know it's text (XML Text to be more specific). I want to create a text file for the CLOB contents from each row in the result set of a query and I'd like to name each file based on the value in a different column in

  • File icons missing in File Panel

    Hi there, I have a brand new installation (demo) of Dreamweaver CS6 on a Mac and in the file panel the icons for files are not there. The icons for folders are there but where there should be an icon for a file there is empty white space. This is fru

  • ARIS - Solution Manager synchronization limitations

    Hello, I made simple demo and I noticed that there are several limitations in ARIS<->Solution Manager synchronization. Could You explain me some issues or tell how to solve them, that would be very helpful. 1. When I make model in SolMan and then imp

  • Report on Account determination errors

    Normally, when billing sometimes you get the account determination errors and then users have to investigate and find solutions.  My user wants to run a report prior to billing to detect any possible errors that prevent the posting to accounting docu

  • I'm not able to set Analog Input voltages, etc

    ok, so i have an NI DAQ I/O card (NI PCI 6723, or something to that effect) and i'm trying to configure the channels for Analog Input signals. when i try to choose any kind of setting for Anolog signal by: >>drop DAQ Assistant vi onto the block diagr