INSERT or UPDATE with multiple rows

Hi there!
I want to ask what I should do in the following case: I have to handle mutliple rows of data to insert OR to update into the database.
The first question is about how to decide whether I should take INSERT or UPDATE. I read here in the forum that I could take a SELECT-statement before, and, if it isn't null, I could update the resultset..if it is null I can make an INSERT-statement.
But now I a have multiple rows to update or to insert which I want to handle as a transaction (with a batch), so I don't want to check each row the way I described above. Does anyone has a hint ?
Thanks a lot in advance.

This is not a problem with java but rather a problem
with databases in general. The solution generally
depends on the data that is being operated on.
If there is a primary key involved, and most records
were expected to NOT be in the database, then you
could just insert them in blocks (transaction/batch).
Each block would fail when a primary key duplicate.
Then you can process each block as individual
l statements. The ones that fail are done as
inserts.
The reverse of the above is used if you expect most
records to be in the database. Do updates and the
break out the blocks with failures to locate the
inserts.
Keep in mind that queries for keys probably will be
faster, but that requires that your keys are ordered.
If you keys are ordered then you can get a range from
the initial data. Use that to query the database for
keys between that range (only return the keys.)
Using the returned keys you can decide whether each
h record needs to be an update or insert (presort the
data into each group and batch each group for more
speed.)
If the data is really mixed and the database supports
it then you can write a stored proc (MySQL does not)
which decides whether an insert/update is needed.
Finally if you have large amounts of data, bulk
operations especially inserts are better done with
tools supplied by the database vendor. Instead of
using JDBC to do the insert/updates you write the
output to a file and pass the file to the tool. You
might use JDBC (again with the ordered key query) to
decide which operation to do. Although faster for
large sets this is problematic due to the error
handling that you have to add.
Thanks for this, jschell. I look for your answers, because they're on the money and written well. I learn a lot from them. - MOD

Similar Messages

  • I have regisetred a EIT with multiple rows Yes, can we change it NO now.

    I have registered a EIT with multiple rows Yes, can we change it NO now.

    Hi,
    Yes you can change this through back-end.
    Register extra information (types) concurrent program run the package HR_REGISTER_EITS and insert definintion of an EIT in respective INFO_TYPES tabel for example if person EIT then definition is stored in PER_PEOPLE_INFO_TYPES.
    In this table we have column MULTIPLE_OCCURENCES_FLAG which can have value as Y or N, Y - Multiple entries allowed, N - Multiple entries not allowed.
    You need to update the value of this flag to N for your EIT definition and you are done.
    Thanks,
    Sanjay

  • JTable with Multiple Row Header

    well, Im do an application thats need formated ISOS Sheets, and most of them have a Table with Multiple Row Header , and Groupable Header, and both of them. I have the .java and in the class MultipleRowHeaderExample calls a class AttributiveCellTableModel for setColumnIdentifiers() and setDataVector() the cue is why this print stack :
    Exception in thread "main" java.lang.StackOverflowError
         at java.util.Vector.<init>(Unknown Source)
         at java.util.Vector.<init>(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:54)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
         at jp.gr.java_conf.tame.swing.table.AttributiveCellTableModel.setDataVector(AttributiveCellTableModel.java:55)
         at javax.swing.table.DefaultTableModel.setColumnIdentifiers(Unknown Source)
    .if in main class, have initialized the data, and column vars
    public class MultipleRowHeaderExample extends JFrame {
      Object[][] data;
      Object[] column;
      JTable table;
      MultiSpanCellTable fixedTable;
      public MultipleRowHeaderExample() {
        super( "Multiple Row Header Example" );
        setSize( 400, 150 );
        data =  new Object[][]{
            {"SNo."    ,"" },
            {"Name"    ,"1"},
            {""        ,"2"},
            {"Language","1"},
            {""        ,"2"},
            {""        ,"3"}};
        column = new Object[]{"",""};
        AttributiveCellTableModel fixedModel = new AttributiveCellTableModel(data, column) {
          public boolean CellEditable(int row, int col) {
            return false;
        };

    What's the code in AttributiveCellTableModel?
    * (swing1.1beta3)
    package jp.gr.java_conf.tame.swing.table;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    * @version 1.0 11/22/98
    public class AttributiveCellTableModel extends DefaultTableModel {
      protected CellAttribute cellAtt;
      public AttributiveCellTableModel() {
        this((Vector)null, 0);
      public AttributiveCellTableModel(int numRows, int numColumns) {
        Vector names = new Vector(numColumns);
        names.setSize(numColumns);
        setColumnIdentifiers(names);
        dataVector = new Vector();
        setNumRows(numRows);
        cellAtt = new DefaultCellAttribute(numRows,numColumns);
      public AttributiveCellTableModel(Vector columnNames, int numRows) {
        setColumnIdentifiers(columnNames);
        dataVector = new Vector();
        setNumRows(numRows);
        cellAtt = new DefaultCellAttribute(numRows,columnNames.size());
      public AttributiveCellTableModel(Object[] columnNames, int numRows) {
        this(convertToVector(columnNames), numRows);
      public AttributiveCellTableModel(Vector data, Vector columnNames) {
        setDataVector(data, columnNames);
      public AttributiveCellTableModel(Object[][] data, Object[] columnNames) {
        setDataVector(data, columnNames);
      public void setDataVector(Vector newData, Vector columnNames) {
        if (newData == null)
          throw new IllegalArgumentException("setDataVector() - Null parameter");
        dataVector = new Vector();
        setColumnIdentifiers(columnNames);
        dataVector = newData;
        cellAtt = new DefaultCellAttribute(dataVector.size(),
                                           columnIdentifiers.size());
        newRowsAdded(new TableModelEvent(this, 0, getRowCount()-1,
               TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
      @Override
      public void setColumnIdentifiers(Vector arg0) {
              // TODO Auto-generated method stub
              super.setColumnIdentifiers(arg0);
      public void addColumn(Object columnName, Vector columnData) {
        if (columnName == null)
          throw new IllegalArgumentException("addColumn() - null parameter");
        columnIdentifiers.addElement(columnName);
        int index = 0;
        Enumeration enumeration = dataVector.elements();
        while (enumeration.hasMoreElements()) {
          Object value;
          if ((columnData != null) && (index < columnData.size()))
           value = columnData.elementAt(index);
          else
         value = null;
          ((Vector)enumeration.nextElement()).addElement(value);
          index++;
        cellAtt.addColumn();
        fireTableStructureChanged();
      public void addRow(Vector rowData) {
        Vector newData = null;
        if (rowData == null) {
          newData = new Vector(getColumnCount());
        else {
          rowData.setSize(getColumnCount());
        dataVector.addElement(newData);
        cellAtt.addRow();
        newRowsAdded(new TableModelEvent(this, getRowCount()-1, getRowCount()-1,
           TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
      public void insertRow(int row, Vector rowData) {
        if (rowData == null) {
          rowData = new Vector(getColumnCount());
        else {
          rowData.setSize(getColumnCount());
        dataVector.insertElementAt(rowData, row);
        cellAtt.insertRow(row);
        newRowsAdded(new TableModelEvent(this, row, row,
           TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
      public CellAttribute getCellAttribute() {
        return cellAtt;
      public void setCellAttribute(CellAttribute newCellAtt) {
        int numColumns = getColumnCount();
        int numRows    = getRowCount();
        if ((newCellAtt.getSize().width  != numColumns) ||
            (newCellAtt.getSize().height != numRows)) {
          newCellAtt.setSize(new Dimension(numRows, numColumns));
        cellAtt = newCellAtt;
        fireTableDataChanged();
      public void changeCellAttribute(int row, int column, Object command) {
        cellAtt.changeAttribute(row, column, command);
      public void changeCellAttribute(int[] rows, int[] columns, Object command) {
        cellAtt.changeAttribute(rows, columns, command);
    }that's it

  • Web dynpro screen with multiple rows with columns that can be edited

    Web dynpro screen with multiple rows with columns that can be edited individually:
    Hi
    I am busy creating a screen in web dynpro for ABAP which we would like to make available via Portal ESS (Portal 7).
    I need to add 'n type of table (or almost something like Excel) or something in which someone can type a few paycode numbers (there should be lets say 10 blank rows in which info can be typed in and if I click on a button or so, more rows must be added if necessary.  Then in the other colums stuff like amounts must be entered which one should also be able to edit then and there.
    Can anyone assist in what I can use for this?  There does not seem to be some existing element that I can use.
    Help will be appreciated.
    Regards
    Debbie

    Hi Debbie,
    Whiel Creating table you need to be care full that use chose INPUT FIELD as the CELL EDITOR. Just guessing that if ur table is not editable u might have choosen TextView as default cell editor type.
    check link for details on TABLE UI
    [http://help.sap.com/saphelp_erp2005/helpdata/EN/b5/ac884118aa1709e10000000a155106/frameset.htm]
    easy way is to first add UI ELEMENT TABLE to your VIEW, then right click over it & select create binding from context. After you have a pop up where you can select what columns you want what should be its cell editor etc.
    Greetings
    Prashant

  • Loading xml file with multiple rows

    I am loading data from xml files using xsl for transformation. I have created xsl's and loaded some of the data. In an xml file with multiple row, it's only loading one (the first) row. Any idea how I can get it to read and load all the records in the file???

    Could some please help me with the above. I desparately need to move forward.

  • TO DRAW A TABLE WITH MULTIPLE ROWS AND MULTIPLE COLOUMNS IN FORM

    Hi,
       How to draw a table with multiple rows and columns seperated by lines in form printing?

    check this
    http://sap-img.com/ts003.htm
    Regards
    Prabhu

  • How to insert a table with variable rows in smart form

    Hi all,
    How to insert a table with variable rows in smart form?
    Any help would be appreciated.
    Regards,
    Mahesh.

    Hi,
    Right click the mouse->create->table
    If you want 5 columns, you need to declare 5 cells in one line type of the table
    Click on Table -> Details, then do the following
    Line Type 1 2 3 4 5
    L1 2mm 3mm etc
    Here specify the width of the columns as many as you want..
    then in the header/main area of the table, click create Table Line, Rowtype is L1, automatically 5 cells will come,In each cell create a text element, display the variable to be printed there.

  • Editable table with multiple rows

    Hi All!
    We're trying to develop some application in VC 7.0. That application should read data from some R/3 tables (via standard and custom functional modules), then display data to user and allow him/her to modify it (or add some data into table rows), and then save it back to R/3.
    What is the best way to do that?
    There's no problem with displaying data.
    But when I try to add something to table (on portal interface), I'm able to use only first row of the table... Even if I fill all fields of that row, I'm not able to add data to second row, etc.
    Second question. Is it possible to display in one table contents of output of several BAPIs? For example we have three bapis, one displaying user, second displays that user's subordinates, and the third one - that user's manager. And we want one resulting table...
    And last. What is the best way to submit data from table view in VC (portal) to R/3 table? I understand that we should write some functional module, that puts data to R/3. I'm asking about what should be done in VC itself. Some button, or action...
    Any help will be appreciated and rewarded :o)
    Regards,
    DK

    Here are some former postings:
    Editable table with multiple rows
    and
    Editable table with multiple rows
    Are you on the right SP-level?
    Can you also split up your posting: one question, one posting? This way you get faster answers, as people might just browse the headers.

  • Table row with multiple row

    Hi All,
    I am using NWDS 2004
    I want to have a table with multiple rows in a row.
    Can any one help ?
    Thanks

    hi Akhilesh,
    Use tree table for your requirement.
    [Tree Table Tutorial|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/de59f7c2-0401-0010-f08d-8659cef543ce]
    Hope this helps!
    Monalisa

  • Downloading .xls file with multiple rows and Columns

    Hi ALL,
    I need to genarate .xls file with multiple rows and and Columns and sent as an email.Since our customer having Problem with .CSV files need to genarate .XLS file.
    Please do the needful.
    Thanks
    Madhu

    Hi Madhu,
    You might also consider using Excel Spreadsheet XML as the target structure (namespace is urn:schemas-microsoft-com:office:spreadsheet).  When you double-click the resulting xml on a PC it automatically opens with Excel. So, users don't see a difference.  It will open up a lot of options with formatting including creating multiple worksheets if you wanted to.  Best of all you can stick with XML.
    See my response in this thread:
    Re: Convert XML data into XLS 
    Thanks,
    -Russ

  • Splitting a message with multiple rows from the JDBC Adapter

    Hi,
    I'd like to split the resultset message with multiple row elements and process each row separately..
    Does someone have this experience?
    Thanx, Peter

    Hi Chandrasekhar,
    I tried to follow your advise, but I'm not able to complete the process correctly.
    Let me explain my process:
    First - output from the JDBC adapter goes into the first receive step. Of course, there are multiple ROW elements. (Should be marked the ingoing message marked in the container as Multiline??)
    The next should be the transformation:
    format of the source message is like
    <message>
      <row>
        <column>w</column>
      </row>
      <row>
        <column>w</column>
      </row>
    </message>
    In the message I have the ROW element as 0..unbounded
    and <column> element exactly 1
    This message should be mapped to multiple messages of the format:
    <message>
      <value>w</value>
    </message>
    How should be the mapping be done?
    Is it N:1 or 1:N (because in another thread there was an 1:N mapping advised)
    Then (as you say) should follow the Block step:
    Which message (container element) should be marked as Multiline? And what does it mean: Current Message?
    Can you give me some advise, when and how to use the multiline mark?
    Thanx a lot, Peter

  • Reg : Concatenation of a column value with multiple rows... URGENT

    Hello,
    Could any of u help me in concatenating a column value with
    multiple rows ???
    For ex : I've the following data from emp table :
    DEPTNO ENAME
    10 KING'S
    30 BLAKE
    10 CLARK
    10 TOM JONES
    30 ALLEN
    30 JAMES
    20 SMITH
    20 SCOTT
    20 MILLER
    10 MILLER
    20 rajeev
    I want the following output :
    deptno Concat_value
    10 KING'S,CLARK,TOM JONES,MILLER
    20 Rajeev,MILLER,SMITH,SCOTT
    30 BLAKE,ALLEN,JAMES
    Thanks in Advance,
    Srini

    Hello Naveen,
    Thanks for ur answer. But I need a single SQL query for getting
    what I want. I know the solution in PL/SQL.
    Please try it in a single SQL....
    Thanks again,
    Srini

  • Watermark with multiple rows of text, Is it possible?

    Hi everyone,
         One of our clients want the whole page filled with watermark with multiple rows of text, I cannot find related properties on the watermark configuration page, is it possible?
    Thank you in advance.

    Multi-line Dynamic Watermarks are available from ES3 onwards. You can create multiple Watermark text elements to have more than one line in the Watermarks. Please see http://help.adobe.com/en_US/livecycle/10.0/AdminHelp/WSb96e41f8a4ca47a94897a78313098c91af6 -8000.html
    Regards,
    Neerav

  • Handling error with multiple row insert/update

    Hi,
    I need to insert multiple rows into a table, and I understand that i need to use executeArrayUpdate().
    My problem is this :
    1. How do I know in case some of the rows in the array failed during the INSERT?
    2. When I do know that, how do I find those particular rows?
    Thanks

    ODAFEONIHOWO wrote:
    Please i need help on how to enter multiple row into mysql with one insert
    statement and jsp it's not possible - you'll need to do a batch insert
    i have been trying this for weeks without sucess e.g how much experience do you have with Java?

  • Single Update command to update multiple rows with multiple rows

    Hi Gurus!
    Can I update table A with a result set of table b (multiple rows returns) where a.c1 = b.c1
    regards,
    SH

    As Joel mentioned this update will update all rows in a table based on another one:
    update tableA set seq_no = (select seqno from tableB where tableA.ID = tableB.ID)
    Also, any rows that don't match the select criteria will get updated to null. This could be very bad depending on what you want to do.
    To update a subset of tableA with data from tableB:
    update tableA set seq_no = (select seqno from tableB where tableA.ID = tableB.ID)
    where exists (select 1 from tableB where tableA.ID = tableB.ID)

Maybe you are looking for

  • Exception while running hello world program

    Hi OAF guys i am getting the following exception when i am trying to run the Hello world example. Any body knows this problem, respond asap Exception Details. oracle.apps.fnd.framework.OAException: Application: FND, Message Name: FND_GENERIC_MESSAGE.

  • Can't Send mail in Mountain Lion Mail

    I am able to receive incoming email in Mail 6.0 but am unable to send messages.  First I got a message that the STMP server did not recognize my email address (nothing had changed other then upgrading to Mountain Lion), I spent some time with my ISP

  • Stream7 - bluetooth audio streaming goes off when i turn the display off!

    I have a hp stream 7 that is connected via bluetooth to my loudspeakers. Everything is fine until the display turns off or i press the power butten to turn off the display. When i turn on the display(press power button) the sound starts and play norm

  • How access control exception is removed

    Pls suggest me how to overcome with this problem . I have only this simple code=============>> public MyRemoteServer() { try { MyRemote c = new MyRemoteImpl(); if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManage

  • BASEFONT in html and pass a value thru a javascript

    Friends I am try to set the size of my text of my entire HTML/JSP document by using the <BASEFONT SIZE ="6"> in the <HEAD> section but it is not working.I mean I want my jsp/html to override the default size set by the users internet explorer setting