How to insert new value into an array

I have an already declared array (including the size) and want to write a method for inserting a new value. Do I have to re-declare the array to the new size? ie old size + 1, then add the new value or is there a java method for this. I can't find one.
Thanks in advance....
Mike

Hi,
there is no method for that. Look up class Vector. That class implements automatic growing of the Vector.
Phil

Similar Messages

  • How to insert column values into database as rows

    Hi,
    I have 8 columns and some not null columns. Based on not null columns I want to insert into table as rows. The 8 columns may contain values or no value. If the first column contains data, then I have to insert into one row. if the second column contains data I have to insert a row and in second column. respectively...So How can I insert column values into rows. Can I write 8 insert statements. (OR) is it possible to insert data from columns using where clause.
    Please help me out....
    Thanks in Advance

    Lines Table:
    line_id, orcl_bank_account_num, product_type, service_type, lease_type,
    funding_type, cpi, billing_frequency_unit_cd , annual_due_date ,
    pricing_start_date, pricing_end_date, install_date, contract_end_date ,
    prdct_replacement_cost_amt, cradle_replacement_amt, supranet_contract,
    issuance_fee, board_inactive_date, header_id, creation_date, last_modified_date,
    created_by_nam, modified_by_nam, activeinactive_flg, prdct_bill_amt_yr1,
    prdct_bill_amt_yr2, prdct_bill_amt_yr3, prdct_bill_amt_yr4, prdct_bill_amt_yr5,
    prdct_bill_amt_yr6, prdct_bill_amt_yr7, prdct_bill_amt_yr8, activation_fee_yr1,
    activation_fee_yr2, activation_fee_yr3, activation_fee_yr4, activation_fee_yr5,
    activation_fee_yr6, activation_fee_yr7, activation_fee_yr8,
    In this table the columns structure is :
    -- PRDCT_BILL_AMT_YR (1 to 8) NUMBER(14,4)
    -- ACTIVATION_FEE_YR (1 to 8) NUMBER(8,2)
    I have one more table:
    PRDCT_INS_AMT               NUMBER(14,4)
    ACTIVATION_FEE_AMT          NUMBER(14,4)
    I want to insert prdct_bill_amt_yr (1 to 8) columns data into PRDCT_INS_AMT column. similarly activation_fee (1 to 8) columns data.
    But the data should be inserted based product_type, service_type, lease_type columns values. (These 3 columns may contain upto 45 combinations).

  • How to insert new values in dropdown box through coding

    hi,
      I want to insert new values in dropdown box in a table.
    Please provide me the corresponding coding.i already did this code but result is empty dropdown.I mapped the context properly..
    int sklength=wdContext.nodeSkills().size();
          for(int i=0;i<sklength;i++)
        String getsub=wdContext.currentSkillsElement().getSubject();
        if(getsub.equals("50000138"))
             //IPrivateDetails1.INewskillElement el=wdContext.createNewskillElement();
             List lis=new ArrayList();
             //lis.add("Abap");
             //lis.add("Workflow");
             IPrivateDetails1.INewskillElement el=wdContext.createNewskillElement();
             el.setTskill("abap");
             lis.add(el);
              el.setTskill("workflow");
              lis.add(el);
              wdContext.nodeNewskill().bind(lis);
              //wdContext.nodeMonthsOfYear().bind(MonthsOfYear);
              wdContext.nodeNewskill().setLeadSelection(1);
        else
              wdContext.currentNewskillElement().setTskill("C++");
    waiting for a positive reply......
    with regards,
    S.Kiruthika

    kiruthika,
    Too many logical errors to explian.
    Should be:
    IPrivateDetails1.ISkillsNode nSkills = wdContext.nodeSkills();
    IPrivateDetails1.INewskillNode nNewSkill = wdContext.nodeNewskill();
    int sklength = nSkills.size();
    boolean cppAdded = false;
    for(int i=0;i<sklength;i++)
      String getsub=nSkills.getSkillsElementAt(i).getSubject();
      if(getsub.equals("50000138"))
        List lis=new ArrayList();
        IPrivateDetails1.INewskillElement el1 = nNewSkill.createNewskillElement();
        el1.setTskill("abap");
        lis.add(el1);
        IPrivateDetails1.INewskillElement el2 = nNewSkill.createNewskillElement();
        el2.setTskill("workflow");
        lis.add(el2);
        nNewSkill.bind(lis);
        nNewSkill.setLeadSelection(1);
      else if (!cppAdded)
        cppAdded = true;
        IPrivateDetails1.INewskillElement elCpp = nNewSkill.currentNewskillElement();   
        if (null ==  elCpp) {
          elCpp = nNewSkill.createNewskillElement();
          nNewskill.addElement(elCpp);
          nNewskill.setLeadSelection( nNewskill.size() - 1);
        elCpp.setTskill("C++");
    VS

  • How to insert a value into a field of binary type?

    I've been using Oracle for a while now but never dealt with BLOB
    or long raw type before. Does anyone here know how to insert a
    record into a field of either blob or long raw type?
    Any suggestions would be very appreicated.
    Thanks.

    pls used the loadfromfile procedure which is in the DBMS_LOB
    package to insert the data from external os file into blob data
    type column.
    Kunjan

  • How to insert new record into altered table

    I am using JDBC with MySQL. I altered existing table and want to insert new record using java class. But it is not possible.How to do?

    How is it "not possible"?
    Either modify the Class for the new fields, or give the new fields default values (if applicable). If the type of an existing column has changed, then only the first option is available.
    Where's the problem?

  • How to insert parameter value into multiple columns and rows

    Hi All,
    I have one procedure insert_tab and I am passing
    100~101~102:103~104~105:106~107~108 as a parameter to that procedure. I wanted to insert each numeric value into one column. The output of the table should contain
    Table:
    Col1 Col2 Col3
    100 101 102
    103 104 105
    106 107 108
    Awaiting for your reply..

    That's not more clear for me...
    Anyway, if you really want a procedure for that, try :
    SQL> create table tblstr (col1 number,col2 number,col3 number);
    Table created.
    SQL>
    SQL> create or replace procedure insert_fct (p_string IN varchar2)
      2  as
      3  v_string     varchar2(4000):=p_string||':';
      4  v_substring  varchar2(4000);
      5 
      6  begin
      7      while instr(v_string,':') > 0 loop
      8            v_substring := substr(v_string,1,instr(v_string,':')-1)||'~';
      9            insert into tblstr(col1,col2,col3)
    10            values (substr(v_substring,1,instr(v_substring,'~',1,1)-1),
    11                    substr(v_substring,instr(v_substring,'~',1,1)+1,instr(v_substring,'~',1,2)-instr(v_substring,'~',1,1)-1),
    12                    substr(v_substring,instr(v_substring,'~',1,2)+1,instr(v_substring,'~',1,3)-instr(v_substring,'~',1,2)-1));
    13            v_string:=substr(v_string,instr(v_string,':')+1);
    14      end loop;
    15  end;
    16  /
    Procedure created.
    SQL>
    SQL> show err
    No errors.
    SQL>
    SQL> select * from tblstr;
    no rows selected
    SQL> exec insert_fct('100~101~102:103~104~105:106~107~108')
    PL/SQL procedure successfully completed.
    SQL> select * from tblstr;
          COL1       COL2       COL3
           100        101        102
           103        104        105
           106        107        108
    SQL> exec insert_fct('109~~')
    PL/SQL procedure successfully completed.
    SQL> exec insert_fct('~110~')
    PL/SQL procedure successfully completed.
    SQL> exec insert_fct('~~111')
    PL/SQL procedure successfully completed.
    SQL> select * from tblstr;
          COL1       COL2       COL3
           100        101        102
           103        104        105
           106        107        108
           109
                      110
                                 111
    6 rows selected.
    SQL> Nicolas.

  • How to insert new record into oracle table from GridView in VS2005.

    I need to insert records into Oracle10g table from VS2005 GridView using the Insert Method in Business Logic Class. The Update and Delete Methods are working fine. What's the best way out?

    How is it "not possible"?
    Either modify the Class for the new fields, or give the new fields default values (if applicable). If the type of an existing column has changed, then only the first option is available.
    Where's the problem?

  • How to insert date value into oracle?

    hi,
    iam reading date from xml using vb.net and inserting it into oracle table.
    the date value in xml file is in the format of "01012003".
    i want to insert into oracle table.but iam getting an error "ORA-1843: not a valid month".
    how to solve this problem.
    Any suggestions or examples...

    That's not a date. It's just a string. Convert it to a date using,
    DateTime d = DateTime.ParseExact("01022003", "MMddyyyy", null);
    or
    Dim d As DateTime = DateTime.ParseExact("01022003", "MMddyyyy", Nothing)
    and then bind it to a parameter. ODP.NET will take it from there.
    You should never be hard-coding the date literal into your SQL query.
    David

  • How to insert a value into a table

    I have an ordering system. It displays all the orders by
    customer ID. If an order is complete, a check number is entered for
    the corresponding line item, otherwise it is left blank.
    My code uses the following code to display the form. All are
    display fields only, except for the last one, where the check
    number can be entered.
    <cfoutput query="qryDetail" group="partNumber">
    <tr>
    <td valign="top" class="TitleText"
    align="center">#lineItem#</td>
    <td valign="top" class="TitleText"
    align="center">#OrderNumber#</td>
    <td valign="top" class="TitleText"
    align="center">#partNumber#</td>
    <td valign="top" class="TitleText"
    align="center">#dollarformat(qryDetail.unitValue)#</td>
    <td valign="top" class="TitleText" align="center">
    <cfinput type="text" name="checkNumber#keyID#">
    <input type="hidden" name="keyID"
    value="#qryDetail.keyID#">
    </td>
    I use something like the following to update the table with
    the check numbers entered.
    <cfloop index="KeyID" list="#form.KeyID#"
    delimiters=",">
    <cfquery name="qryUpdate" datasource="dbName">
    update tblChecks
    set checkNumber = '#Evaluate("form.checkNumber#KeyID#")#'
    where custID = '#form.custID#'
    and KeyID = '#KeyID#'
    </cfquery>
    </cfloop>
    Now we have another table that will contain the customer
    order history. If the check number was entered for a particular
    line item, I need to insert that line item nubmer into this table,
    along with some other columns. I tried to use the same loop, then
    other loops, but cannot seem to get this to work. Seems simple
    enough, but I obvisouly am missing something.
    How would I insert the line item number (only if a check
    number was entered for that line item) into the table ?

    Here is the code with the queries commented out :
    <cfloop list="#form.fieldnames#" index="field">
    <cfif left(field, 11) is "checkNumber" AND
    len(trim(form[field]))>
    <cfset keyID = listlast(field, '_')>
    <cfset lineItem = listgetat(field, 2, '_')>
    <cfset checknum = form[field]>
    <!---cfquery name="qryUpdate" datasource="dbName">
    UPDATE tblChecks
    SET checkNumber = '#checknum#'
    WHERE custID = #form.custID#
    AND KeyID = #keyid#
    </cfquery--->
    <cfoutput> loop is
    field: <b>#field#</b><br>
    checknum: #checknum#<br>
    lineitem: #lineitem#<br>
    keyID: #keyID#<br>
    </cfoutput>
    <cfelse>
    <cfoutput>Else is
    field: <b>#field#</b><br>
    form[field]: #form[field]#<br>
    len: #len(trim(form[field]))#<br>
    </cfoutput><cfabort>
    </cfif>
    </cfloop>
    This is the output. If I do not put in cfabort, the code just
    drops thru and I never see any output display, so I use cfabort to
    stop so I can see the output.
    loop is field: CHECKNUMBER_11_218
    CHECKNum: xxxxxxxxxxxxxxxxxxxx
    lineitem: 11
    keyID: 218
    Else is field: CHECKNUMBER_1_24
    form[field]:
    I entered the x's into checknum for line item 11, so that is
    correct.
    I then took out the comments from the update query and tried
    it again and it updated for line item 11 (you were right, I had to
    take out the single quotes in the query). I then removed the
    commets for the insert query and it did not insert. I tried the
    whole thing again and tried to add to line item 10 and it dropped
    straight to the else part, displaying :
    Else is field: CHECKNUMBER_1_24
    form[field]:
    len: 0
    So it seems the if statement if failing the second time thru
    the loop :
    <cfif left(field, 11) is "checkNumber" AND
    len(trim(form[field]))>
    This is my input statement :
    <cfinput type="text"
    name="checkNumber_#lineItem#_#keyID#">
    I am really confused now. It seems to work the first time
    thru the loop, then the second time it fails.

  • How to insert object values into table.

    Hi All,
    I have a problem with passing java object to procedure. Procedure is running properly when I execute in oracle,but it is not executing when I call from Java.
    I am getting Error :
    java.sql.SQLException: invalid name pattern: Pkg_Bulk_Insert.ITW_EMP_OBJ_ARRAY
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
         at oracle.jdbc.oracore.OracleTypeADT.initMetadata(OracleTypeADT.java)
         at oracle.jdbc.oracore.OracleTypeADT.init(OracleTypeADT.java)
         at oracle.sql.ArrayDescriptor.initPickler(ArrayDescriptor.java)
         at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java)
         at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java)
         at JavaObjectToOracle.main(JavaObjectToOracle.java:31)
    Here I am copying my procedure,oracle version is 9i.
    Package specification:
    CREATE OR REPLACE PACKAGE Pkg_Bulk_Insert AS
    TYPE ITW_EMP_OBJ_ARRAY IS VARRAY(20) OF VARCHAR2(200);
    PROCEDURE BULK_INSERT_TEST(strTable IN ITW_EMP_OBJ_ARRAY);
    END Pkg_Bulk_Insert;
    package body:
    CREATE OR REPLACE PACKAGE BODY Pkg_Bulk_Insert AS
    PROCEDURE BULK_INSERT_TEST(strTable IN ITW_EMP_OBJ_ARRAY) AS
    i BINARY_INTEGER;
    BEGIN
    FORALL i IN 1..strTable.COUNT
    INSERT INTO TEMP(NAME)
    VALUES(strTable(i));
    COMMIT;
    END BULK_INSERT_TEST;
    END Pkg_Bulk_Insert;
    Here I am invoking the procedure:
    DECLARE
    x Pkg_Bulk_Insert.ITW_EMP_OBJ_ARRAY;
    BEGIN
    x := Pkg_Bulk_Insert.ITW_EMP_OBJ_ARRAY('A','B','C');
    Pkg_Bulk_Insert.BULK_INSERT_TEST(x);
    DBMS_OUTPUT.PUT_LINE('AFTER INSERTION');
    END;
    Please any body can help me on this regard.

    Your PL/SQL seems reasonable.
    My suspicion would be that the oracle.sql.ArrayDescriptor.createDescriptor class only supports persistent collection types, i.e. those declared at the schema level with CREATE TYPE.

  • Sqlloader: how to insert -ve value into table

    hi..
    i had problem during loading. The error is Record 1: Rejected - Error on table FILE01, column AMOUNT.
    ORA-01722: invalid number
    For AMOUNT, the datatype is number(20,2).
    here is my .ctl
    LOAD DATA
    INFILE 'file1bp0103.txt'
    BADFILE 'file01.bad'
    APPEND
    INTO TABLE file01
    acct_no POSITION(01:13),
    amount POSITION(14:28),
    description POSITION(29:32)
    my .dat file
    A500000030401- 32.74PYMT
    A500000320106- 46.95PYMT
    A500000520408- 63.95PYMT
    A500000610301- 12.99PYMT
    A500001720110- 56.21PYMT
    A500001800103- 55.65PYMT
    A500002000109- 27.25PYMT
    A500002000305- 53.35PYMT
    A500002080210- 75.04PYMT
    A500002250106- 103.38PYMT
    A500002500104- 60.69PYMT
    A500002620902- 509.77PYMT
    A500002621010- 398.69PYMT
    what is the problem? is it because of my datatype?
    please help me..
    TQ

    Is there a need to use dynamic sql here?
    at the very least, try using bind variables instead of concatenating values like that.
    EXECUTE IMMEDIATE 'insert into your_table (column_list) values (:val1, :val2, ...)'
    USING l_val1, l_val2, l_val3 ... ;

  • Hihow to insert 2 elements into 2D array?

    Hi I had a hard time figuring out how to insert 2 elements into 2D arrays. 
    I tried using replace and insert array functions but it does not work right way.
    I am using LV7.1. See the pic below.
    How do I insert elements in that way?
    Pls advise
    Clement

    Well, "replace array subset" is not the right tool, because it keeps the size of the array constant. Insert into array only works for entire rows or columns.
    You need a hybrid approach, because you want to insert elements at the beginning of column 1 while padding the remaining columns to the new lenght of column 1. This won't be efficient but there are plenty of ways to do that (here is one example with DBL arrays, should work equally well for string arrays as in your case).
    How much flexibility do you need? Is it always at the beginning of the first column? Are the arrays huge (=is performance an issue)? Is this a rare operations or do you constantly need to do this (e.g. inside a loop).
    In any case this seems like a rather arbitrary and somewhat silly operation. What is the practical purpose?
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    WeirdMerge.vi ‏21 KB

  • Last One I Promise! Inserting A Value In An Array And Shifting TheRest Over

    Last question I have, I need to know the theory behind inserting a value into an array and shifting the rest over.. I have somewhat of an idea and that is this:
    Obviously I need to use a for loop, and a temp value to hold each value until it shifts then move on to the next value? Oh and increase the size of the array by one? I'm having trouble making sense of it..
    lets say we have the same array as from before
              int[] aRay = new int[5];
              aRay[0] = 1;
              aRay[1] = 9;
              aRay[2] = 3;
              aRay[3] = 4;
    aRay[4] = 11;
    and we want to add... lets say the element 5 into the index spot of 2 is and shift 2 to 3 and 3 to 4 and 4 to 5.
    for ( int i = 0; i < aRay.length; i++) // this will move along each element of the array (so I know I need this for sure)
    Am I on the right track? thanks all
    Edited by: Jojobaba on May 13, 2008 11:50 PM
    Edited by: Jojobaba on May 13, 2008 11:54 PM

    Jojobaba wrote:
    I can do all that, the only trouble I'm having right now is what's the correct way to increase the size of the array by one more? if I try to declare 4 as 5 it gives me a runtime error because 5 is out of bounds, and rightly so, because it doesn't exist
    Once I get that, the rest will be cake
    int[] aRay = new int[5];
    ^
    l
    l
    Do I just make this a 6? or is that not the right way.. :/You can't change array sizes dynamically. You will have to make a new array of the appropriate size and copy into it. You could use copyOf: http://java.sun.com/javase/6/docs/api/java/util/Arrays.html#copyOf(int[],%20int)
    I hope this is purely an academic exercise, because there's no reason to do this.

  • Inserting new records into database table at runtime

    Hi all ,
    How to insert new records into database table at runtime on click update?
    Thanks.

    Hi Sasikala,
    Just for your understanding am giving a sample code snippet which you can use to read the contents of your Table UI element & save the data on to your database. Suppose you have a button up on pressing which you want to read the data from your screens table & save on to the database then you can proceed as shown below:
    1) Obtain the reference of your context node.
    2) Fetch all the data present in your table into an internal table using methods of if_wd_context_node
    3) Use your normal ABAP logic to update the database table with the data from your internal table
    In my example I have a node by name SFLIGHT_NODE and under this I have the desired attributes from SFLIGHT. Am displaying these in an editable table & the user would press up on a push button after making the necessary changes to the tables data. I would then need to obtain the tables information & save on to the database.
    data: node_sflight           type ref to if_wd_context_node,
            elem_sflight           type ref to if_wd_context_element,
            lt_elements            type WDR_CONTEXT_ELEMENT_SET,
           stru_sflight           type if_main=>element_sflight_node,
           it_flights             type if_main=>elements_sflight_node.
    "   navigate from <CONTEXT> to <SFLIGHT_NODE> via lead selection
        node_sflight_node = wd_context->get_child_node( name = 'SFLIGHT_NODE'  ).
       lt_elements = node_sflight->get_elements( ).
    "   Get all the rows from the table for saving on to the database
        loop at lt_elements into elem_sflight.
          elem_sflight->get_static_attributes( importing static_attributes = stru_sflight ).
          append stru_sflight to it_flights.
        endloop.
    " Finally save the entries on to the database
        modify ZSFLIGHT99 from table it_flights.
        if sy-subrc eq 0.
    endif.
    However a word of caution here.... SAP doesn't ever recommend directly modifying the database through an SQL query. You would preferably make use of a BAPI for the same. Try go through Thomas Jung's comments in [here|modify the data base table which is comming dynamiclly;.
    Regards,
    Uday

  • How to insert values into an array of class

    Hello everyone,
    I need help in inserting values into an array of class, which i have read from a file.
    Length of the array is 5. I should insert values one by one into that array.
    If the array is full (if count = 5), then I should split the array into 2 arrays
    and adjust the values to left and right with median.
    I'm getting an ArrayBoundException .. can anybody help me out ?
    Thanks in advance
    Here is my code..........
    import java.util.*;
    import java.io.*;
    public class Tree
         static String second;
         static String first;
         static int count = 5;
         public void insert(int f1,int s1, int c)
              if(c!=0)
                   Record[] rec = new Record[4];
                   for (int i = 0; i < 5; i++)
                          rec[i] = new Record(); 
                   for(int i = 0; i<=4;i++)
                        rec.x = f1;
                        rec[i].y = s1;
              else
                   System.out.println("yes");
         public static void main(String[] args)
              Tree t = new Tree();
              try
                   FileReader fr = new FileReader("output.txt");           // open file
                   BufferedReader br = new BufferedReader(fr);
                   String s;
                   while((s = br.readLine()) != null)
                        StringTokenizer st = new StringTokenizer(s);
                        while(st.hasMoreTokens())
                             first = st.nextToken();
                             second = st.nextToken();
                        //     System.out.println("First-->"+first+" "+"Second-->"+second);
                        int fir = Integer.parseInt(first);
                        int sec = Integer.parseInt(second);
                        t.insert(fir, sec, count);                    
                   fr.close(); // close file           
              catch (IOException e)
    System.out.println("Can't read file");
    class Record
         public int x,y;

    Hi qwedwe.
    Record[] rec = new Record[4];
                   for (int i = 0; i < 5; i++)
                          rec[i] = new Record(); 
                     }Here is your error: you have an array of 4 Records, but you create and (try to) insert 5 Record-instances.... try:
    Record[] rec = new Record[c];
                   for (int i = 0; i < c; i++)
                          rec[i] = new Record(); 
                     }Regards,
    Norman

Maybe you are looking for