Data query and insert rows performance

We are currently getting a system developed in Unix/Weblogic/Tomcat/Oracle environment. We have developed a screen that contains 5 or 6 different parameters to select from. We could select multiple parameters in each of these selections. The idea behind the subsequent screens is to attach information to already existing data/ possible future data that matches the selection criteria.
Based on these selections, existing data located within the system in a table is searched and those that match are selected. Also new rows are created in the table against combinations that do not currently have a match. Frequently multiple parameters are selected, and 2000 different combinations need to be searched in the table. Of these selections, only about 100 or 200 combinations will be available in existing data. So the system is having to insert 1800 rows. The user meanwhile waits for the system to come up with data based on their selections. The user is not willing to wait more than 30 seconds to get to the next screen. In the above mentioned scenario, the system takes more than an hour to insert the new records and bring the information up. We need suggestions to see if the performance can be improved this drastically. If not what are the alternatives? Thanks

Are the tables have latest statsitics?
Take the statspack report and pay attention to the top 5 timed events. I would suggest you to get the session waits during this scinario.
Other workaround would be to trace the session with 10046, format with tkprof and analyze the explain plan of the queries.
Jaffar

Similar Messages

  • Select query and Insert statement performance

    Hi all,
    Can anyone plz guide us on below problem I am facing ?
    1) One of the simple Insert statement runs very slow..What might be the reason? Its simple table without any LOBs ,LONG or so. Everything else in the DB works fine.
    2) one of the SELECT statement runs very slow. It selects all records (around 1000) from a table..How can i improve its performance?
    3)Which columns in the Master and its detail tables should be indexed to improve Query performance on them.
    Many Thanks
    Regards
    sandeep

    To get an answer to your questions you have to post some informations about your system:
    1. operating system
    2. RAM
    3. oracle version
    4. init.ora
    Thomas

  • Compare 2 tables and insert rows missing in each table.

    I have a tough situation. I have two exact tables- one online and one offline database. I know that there are missing rows of data from each table, so I need to make a comparison of one table and insert rows that do not exist. I was thinking to try this, but it took over 3 hours to run and did not return anything:
    insert into t
    select * from t a
    where not exists (select * from [email protected] b
    where a.col1 != b.col1
    and a.col2 != b.col2
    and a.col3 != b.col3);
    and it goes on for another 7columns.
    The trouble I have is to include a date clause so that the query can be broken down into running only a few months of data comparisions at a time- the records go back 4 years to compare. Also is there a way to write this so that it will query both tables at the same time in order to speed things up- or is one table at a time the best advice? Each table has over 100 million records to compare, that's why I was hoping to use a date criteria since one column is date.
    Let me know what you advise to make this work, I hope I was on the right track.

    Not sure if the MINUS operator will perform better with your data set but;
    SQL> create table t1 (some_id number, some_date date)
    Table created.
    SQL> create table t2 (some_id number, some_date date)
    Table created.
    SQL> insert into t1 values (1, trunc(sysdate))
    1 row created.
    SQL> insert into t1 values (2, trunc(sysdate-5))
    1 row created.
    SQL> insert into t1 values (4, trunc(sysdate-90))
    1 row created.
    SQL> insert into t2 values (1, trunc(sysdate))
    1 row created.
    SQL> insert into t2 values (3, trunc(sysdate-10))
    1 row created.
    SQL> insert into t2 values (5, trunc(sysdate-100))
    1 row created.
    SQL> select * from t1
       SOME_ID SOME_DAT
             1 07-07-30
             2 07-07-25
             4 07-05-01
    3 rows selected.
    SQL> select * from t2
       SOME_ID SOME_DAT
             1 07-07-30
             3 07-07-20
             5 07-04-21
    3 rows selected.
    SQL> insert into t1 (
       select some_id, some_date from t2 where some_date between sysdate-50 and sysdate
       minus
       select some_id, some_date from t1 where some_date between sysdate-50 and sysdate)
    1 row created.
    SQL> insert into t2 (
       select some_id, some_date from t1 where some_date between sysdate-50 and sysdate
       minus
       select some_id, some_date from t2 where some_date between sysdate-50 and sysdate)
    1 row created.
    SQL> select * from t1
       SOME_ID SOME_DAT
             1 07-07-30
             2 07-07-25
             4 07-05-01
             3 07-07-20
    4 rows selected.
    SQL> select * from t2
       SOME_ID SOME_DAT
             1 07-07-30
             3 07-07-20
             5 07-04-21
             2 07-07-25
    4 rows selected.

  • SQL Loader and Insert Into Performance Difference

    Hello All,
    Im in a situation to measure performance difference between SQL Loader and Insert into. Say there 10000 records in a flat file and I want to load it into a staging table.
    I know that if I use PL/SQL UTL_FILE to do this job performance will degrade(dont ask me why im going for UTL_FILE instead of SQL Loader). But I dont know how much. Can anybody tell me the performance difference in % (like 20% will decrease) in case of 10000 records.
    Thanks,
    Kannan.

    Kannan B wrote:
    Do not confuse the topic, as I told im not going to use External tables. This post is to speak the performance difference between SQL Loader and Simple Insert Statement.I don't think people are confusing the topic.
    External tables are a superior means of reading a file as it doesn't require any command line calls or external control files to be set up. All that is needed is a single external table definition created in a similar way to creating any other table (just with the additional external table information obviously). It also eliminates the need to have a 'staging' table on the database to load the data into as the data can just be queried as needed directly from the file, and if the file changes, so does the data seen through the external table automatically without the need to re-run any SQL*Loader process again.
    Who told you not to use External Tables? Do they know what they are talking about? Can they give a valid reason why external tables are not to be used?
    IMO, if you're considering SQL*Loader, you should be considering External tables as a better alternative.

  • Set_ready_for_input  and insert row.

    hy guys, i having an issue with an alv oo.
    i have created a button on my toolbar to make my alv editable by using
    if grid->is_ready_for_input( ) EQ 0.
    CALL METHOD grid->set_ready_for_input
        EXPORTING i_ready_for_input = 1.
    and that works fine.
    all the editable fields are in edit mode (all non keywords fields).
    the issue is this, i want the user  to be able to insert a new row.
    When the alv switches to the edit mode, 2 buttons add row and delete row are automatically add to the toolbar.
    But when you have a new row, that row should completely be editable, but in my case the row is non editable.
    so where does the event add rows is triggered? when i'm trying to debug the adding row action, the program never stop, add immediately the row.
    I try to see if the handle data changed was trigged but neither this was triggered.
    How can i make the added to be immediately editable?
    Edited by: EBONGUE ANDRE on May 27, 2010 4:08 PM

    You should also set the EDIT option in your Layout.
        gs_layout-edit = 'X'.
        CALL METHOD g_grid->set_table_for_first_display
             EXPORTING i_structure_name = 'SFLIGHT'
                       is_layout        = gs_layout   " <
             CHANGING  it_outtab        = gt_outtab.
    Check program BCALV_EDIT_01.
    Regards,
    Naimesh Patel

  • Read a file and insert rows into table

    Hi,
    i would like to know how read a file (expl.txt) with the utl_file package and after insert each row into the table (dataID).
    ie :
    file /tmp/expl.txt is containing :
    id1 id2 describe
    2 3 test1
    6 5 test2
    4 7 test3
    and
    table dataID (
    id1 number,
    id2 number,
    describe varchar2(100));
    Thanks you very much.

    Hello,
    You can use the TEXT_IO package.
    Perform an over-all search (right upper corner) on TEXT_IO, and in the results you will find a manual on how to use the package.
    Hope this will help you.
    Regards,
    Cindy

  • Cfloop query and last row

    Hello everyone,
    I was trying looping over a query which has to be executed
    only when the last row of a previous loop has been reached. The
    question is: I have nested loops, I am able to print the values
    based on two loops:
    for example: <cfloop query="advisor">
    <cfloop students>
    </cfloop>
    </cfloop>
    I am able to get student values for a particular advisor and
    print the values for different advisor and students. I am trying to
    include another loop like grades within advisor loop which should
    be executed at the end of students list for that particular
    advisor. What I am doingg right now is displaying the values in a
    table format.
    <table>
    <tr>Advisor</tr>
    <tr>Student1<tr>
    <tr>Student2</tr>
    <tr>Grades</tr>
    How is possible to know when I would reach the end of the
    student loop for an advisor and then loop the grades for the same
    advisor before proceeding to another advisor?
    Any suggestions would be great.
    Thanks.

    The group attribute of cfoutput would be a lot more
    efficient. Useage is described in the cfml reference manual. If you
    don't have one, the internet does.
    It would also be more efficient to get all your data with a
    single query.

  • MAX(ROWID) and inserting rows at the end of the table

    Hi,
    I know this will be another lame question but I simply didn't find the answer anywhere. I create ID (primary key) for rows manually so I have this code:
    String query = "SELECT * FROM CIS_SEG_SKUPINY WHERE ROWID=(SELECT MAX(ROWID) FROM CIS_SEG_SKUPINY)";
    rset = stmt.executeQuery(query);
    if (!rset.next()) {
    <p style="padding-left:10px">newID = new Number(1);
    System.out.println(newID);</p>
    else {
    <p style="padding-left:10px">rset.beforeFirst();
    while (rset.next()) {
    <p style="padding-left:20px">int lastID = rset.getInt("ID");
    System.out.println(lastID);
    newID = new Number(lastID + 1);
    System.out.println(newID);
    }</p>
    }</p>
    css.setId(newID);
    Row globalsRow = getGlobals().first();
    css.setKodSegSkupiny((String)globalsRow.getAttribute("GroupCode"));
    css.setPopis((String)globalsRow.getAttribute("Description"));
    css.setBarva((Number)globalsRow.getAttribute("Colour"));
    getDBTransaction().commit();
    When the table is empty newID is set to 1 and row inserted. Now I have one row in the table (with ID=1) so newID is set to 2 and row inserted BUT it is inserted BEFORE the first row. So when I try to insert third row lastID is 1 not 2. I tried to find some command which would insert new row after the last one but unfortunately I wasn't successfull.
    Edited by: Herald on Mar 28, 2009 11:11 AM

    Herald,
    I am sorry to say that there are so many things wrong with your approach, that I don't know where to begin...
    1). ROWID is a pseudo column in Oracle.. It has no meaning of first, last, middle, or otherwise. SELECT MAX(ROWID) will get you some row.
    2). In a relational database, there is no concept of first or last row in a table. If you expect the rows in some order, use an order by.
    3). Ignoring your implementation and addressing your intent - you should not be creating a primary key by getting the max already in the table and adding one. You will, using your technique, get duplicates in a multi-user scenario. If you fix your implementation to not give duplicates in a multi-user scenario (no, I won't show you how), you will use a table lock, and therefor inhibit scalability in a serious way.
    The proper and commonly accepted way to generate a numeric primary key in Oracle would be to use a sequence and a trigger to populate the sequence. Lots of examples to be found in this forum, but just have a read of the ADF Developers Guide for Forms/4GL Developers (for 10g) or the Fusion Developers Guide (for 11g) to find one. The term to search for would be DBSequence.
    John

  • XML data extraction and new row display

    I have a table named, SAPDATABROWSER, which has multiple columns and rows. A column named SAPTEXT (DataType: CLOB) consist of xml data. Each XML data is different in terms of number of nodes, but has the same following structure:
    <SAP_BAPI_PROP>
    <SelectedProperty>
    <Structure>
    <Field></Field>
    <Length></Length>
    <FieldValue></FieldValue>
    <Type></Type>
    <Priority></Priority>
    </Structure>
    </SelectedProperty>
    </SAP_BAPI_PROP>
    So now what I would like to do is, to extract the values: Field, FieldValue and Length from every row (total 72) and display the result as following,
    Field FieldValue Length
    XXXX YYYY ZZZZ
    PPPP QQQQ RRRR
    AAAA BBBB CCCC
    MMMM NNNN OOOO
    Again, each row (total 72) has multiple nodes inside XML data, i.e there are multiple Field,Length and FieldType Nodes and no two XML row/data are similar!
    I am using the following code:
    SELECT
    EXTRACT (xmltype (saptext), '/SAP_BAPI_PROP/SelectedProperty/Structure/Field/text()'),
    EXTRACT (xmltype (saptext), '/SAP_BAPI_PROP/SelectedProperty/Structure/Length/text()' ),
    EXTRACT (xmltype (saptext), '/SAP_BAPI_PROP/SelectedProperty/Structure/FieldValue/text()' )
    FROM sapdatabrowser ;
    The above code generate result as following:
    /SAP_BAPI_PROP/..../Field/text() /SAP_BAPI_PROP/..../Length/text() /SAP_BAPI_PROP/..../FieldValue/text()
    1. XXXXPPPPAAAA YYYYQQQQBBBB ZZZZRRRRCCCC
    2. MMMM NNNN OOOO
    Any suggestions?! Thank you very much. :)

    Thank you everyone for your input. But I am still stuck. Let me start with my SQL version:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - ProductionI believe my explaination was not clear so let me rephrase my question. Following is a screenshot of the Table SAPDATABROWSER
    http://img585.imageshack.us/img585/2724/55760509.jpgSo there are total 72 rows, and my interest is in Column 6, SAPTEXT (type:CLOB). Each of the row has following structure:
    <SelectedProperty>
    <Structure>
    <Field></Field>
    <Length></Length>
    <FieldValue></FieldValue>
    <Type></Type>
    <Priority></Priority>
    </Structure>
    </SelectedProperty>Each row has multiple nodes Field, Length, FieldValue.... etc. Now I would like to extract ALL: Field, Length and FieldValue nodes from ALL rows and display them in following format
    Field                  Length                   FieldValue
      1                       1                           1
      2                       2                           2
      3                       3                           3
      4                       4                           4Example Output:
    ROW 1:
    <SelectedProperty>
    <Structure>
    <Field>X</Field>
    <Length>Y</Length>
    <FieldValue>Z</FieldValue>
    <Type></Type>
    <Priority></Priority>
    </Structure>
    <Structure>
    <Field>P</Field>
    <Length>Q</Length>
    <FieldValue>R</FieldValue>
    <Type></Type>
    <Priority></Priority>
    </Structure>
    </SelectedProperty>
    ROW 2:
    <SelectedProperty>
    <Structure>
    <Field>A</Field>
    <Length>B</Length>
    <FieldValue>C</FieldValue>
    <Type></Type>
    <Priority></Priority>
    </Structure>
    <Structure>
    <Field>M</Field>
    <Length>N</Length>
    <FieldValue>O</FieldValue>
    <Type></Type>
    <Priority></Priority>
    </Structure>
    </SelectedProperty>Required Output:
    Field                  Length                   FieldValue
      X                       Y                           Z
      P                       Q                           R
      A                       B                           C
      M                       N                           O

  • Dynamically creating table and inserting rows and columns using JSP

    Hi,
    I'm using mysql and JSP to create web interface for my forms/tables. I wanna create the table dynamically depending on the data in the table and for each particualar record. and these values shud be loaded on the form after loading from the databaes as soon as the form loads.
    also i want to have a button which shud add new rows dynamically. and same one for columns.
    how do i calculate the values across the rows on the forms
    I'm new to JSP. Please point me in the right direction...any tutorials or code will be helpful.
    Any help is appreciated.
    Thanks
    Ayesha

    u write the code in sequence:
    1 write jdbs to select count(* )from table
    2 put in array e.g. String doc_no=new String[count];
    3 write jdbs to select * from table with condition
    //for no. of records just write
    for(int j=0;j<(count);j++){
    <% while(rs4.next()){
         doc_no=rs4.getString(2);
                        date1[i]=rs4.getString(3);
         doc_type[i]=rs4.getString(4);
         location[i]=rs4.getString(5);
         cheque[i]=rs4.getString(6);
         rate[i]=rs4.getInt(7);
         deb_qty[i]=rs4.getInt(8);
         cre_qty[i]=rs4.getInt(9);
         deb_amt[i]=rs4.getInt(10);
         cre_amt[i]=rs4.getInt(11);
         i++;
         //rs4.close();
                   for(int j=0;j<(count);j++){
                   System.out.println("Data count= "+j);
                   %>
    <tr>
    <td width="15%"><font size="1"><%=doc_no[j] %></font></td>
    <td width="10%"><font size="1"><%=date1[j] %></font></td>
    <td width="12%"><font size="1"><%=doc_type[j] %></font></td>
    <td width="9%"><font size="1"><%=location[j] %></font></td>
    <td width="9%">
    <div align="left"><font size="1"><%=cheque[j] %></font></div>
    </td>
    <td width="8%">
    <div align="right"><font size="1"><%=deb_qty[j] %></font></div>
    </td>
    <td width="8%">
    <div align="right"><font size="1"><%=cre_qty[j] %></font></div>
    </td>
    <td width="9%">
    <div align="right"><font size="1"><%=deb_amt[j] %></font></div>
    </td>
    <td width="10%">
    <div align="right"><font size="1"><%=cre_amt[j] %></font></div>
    </td>
    </tr>
    write if there is any specific problem
    bye,
    Samir

  • How to insert the Formatted date value and insert into the database

    Hi All,
    I am having requirement of inserting the date value in to the datbase. I'm already getting the value from file as MM-DD-YYYY. Getting exception while transforming the values through the transform activity. I'm using format fate function but it is inserting null value in to the database.
    Any help from anyone would bve appreciated.
    Thanks,
    CH

    Hi,
    your input date format is fixed right? So, in the transform you can split each your date, which is in 'MM-DD-YYYY' format ... extract day, month, year.
    After that ... just put these values in order acording to the format of 'xsd:date' data type which is '[-]CCYY-MM-DDZ'.
    XPath function 'xp20:format-dateTime()' works only with 'xsd:dateTime' data type, which has format '[-]CCYY-MM-DDThh:mm:ssZ'.
    So, in your case it could be:
    <xsl:variable name="day" select="substring($inputDate,4,2)"/>
    <xsl:variable name="month" select="substring($inputDate,1,2)"/>
    <xsl:variable name="day" select="substring($inputDate,7,4)"/>
    <xsl:variable name="outputDate">
    <xsl:value-of select="$year"/>
    <xsl:text>-</xsl:text>
    <xsl:value-of select="$month"/>
    <xsl:text>-</xsl:text>
    <xsl:value-of select="$day"/>
    </xsl:variable>
    Regards,
    Martin.

  • Removing rows and inserting new rows with new data in JTAble!!! (Plz. help)

    I have a problem, The scenario is that when I click any folder that si in my JTable's first row, the table is update by removing all the rows and showing only the contents of my selected folder. Right now it's not removing the rows and instead throwing exceptions. The code is attached. The methods to look are upDateTabel(...) and clearTableData(....), after clearing all my rows then I proceed on adding my data to the Jtable and inserting rows but it's not being done. May be I have a problem in my DefaultTableModel class. Please see the code below what I am doing wrong and how should I do it. Any help is appreciated.
    Thanks
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.text.SimpleDateFormat;
    import java.util.*;
    public class SimpleTable extends JPanel{
         /** Formats the date */
         protected SimpleDateFormat           formatter;
    /** variable to hold the date and time in a raw form for the directory*/
    protected long                          dateDirectory;
    /** holds the readable form converted date for the directories*/
    protected String                     dirDate;
    /** holds the readable form converted date for the files*/
    protected String                     fileDate;
    /** variable to hold the date and time in a raw form for the file*/
    protected long                          dateFile;
    /** holds the length of the file in bytes */
    protected long                         totalLen;
    /** convert the length to the wrapper class */
    protected Long                         longe;
    /** Vector to hold the sub directories */
    protected Vector                     subDir;
    /** holds the name of the selected directory */
    protected String                    dirNameHold;
    /** converting vector to an Array and store the values in this */
    protected File                     directoryArray[];
    /** hashtable to store the key-value pair */
    protected static Hashtable hashTable = new Hashtable();
    /** refer to the TableModel that is the default*/
    protected MyTableModel               tableModel;
    /** stores the path of the selected file */
    protected static String               fullPath;
    /** stores the currently selected file */
    protected static File selectedFilename;
    /** stores the extension of the selected file */
    protected static String           extension;
    protected int COLUMN_COUNT = 4;
         protected Vector data = new Vector( 0, 1 );
         protected final JTable table;
    /** holds the names of the columns */
    protected final String columnNames[] = {"Name", "Size", "Type", "Modified"};
    public SimpleTable(File directoryArray[])
              this.setLayout(new BorderLayout());
              this.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
              (SimpleTable.hashTable).clear();
              formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
              for(int k = 0; k < directoryArray.length; k++)
                   if(directoryArray[k].isDirectory())
                        dateDirectory = directoryArray[k].lastModified();
                        dirDate = formatter.format(new java.util.Date(dateDirectory));
                        data.addElement( new MyObj( directoryArray[k].getName(), "", "File Folder", "" + dirDate ) );
                        (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);                    
                   else if(directoryArray[k].isFile())
                        dateDirectory = directoryArray[k].lastModified();
                        fileDate = formatter.format(new java.util.Date(dateDirectory));
                        totalLen = directoryArray[k].length();
                        longe = new Long(totalLen);
                        data.addElement( new MyObj( directoryArray[k].getName(), longe + " Bytes", "", "" + fileDate ) );
                        (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
    tableModel = new MyTableModel();
              table = new JTable( tableModel );
              table.getTableHeader().setReorderingAllowed(false);
              table.setRowSelectionAllowed(false);
              table.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
              table.setShowHorizontalLines(false);
              table.setShowVerticalLines(false);
              table.addMouseListener(new MouseAdapter()
    public void mouseReleased(MouseEvent e)
         Object eventTarget = e.getSource();
                        if( eventTarget == table )
                             upDateTable(table);
                             table.tableChanged( new javax.swing.event.TableModelEvent(tableModel) ) ;
              DefaultTableCellRenderer D_headerRenderer = (DefaultTableCellRenderer ) table.getTableHeader().getDefaultRenderer();
              table.getColumnModel().getColumn(0).setHeaderRenderer(D_headerRenderer );
              ((DefaultTableCellRenderer)D_headerRenderer).setToolTipText("File and Folder in the Current Folder");
    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this window.
    this.add(scrollPane, BorderLayout.CENTER);
    * Searches the Hashtable and returns the path of the folder or the value.
    public File findPath(String value)
         return (File)((SimpleTable.hashTable).get(value));
    * This clears the previous data in the JTable
    public void clearTableData(JTable table)
         for(int row = 0; row < table.getRowCount() ; row++)
                   //for (int col = 0; col < table.getColumnCount() ; col++)
                        tableModel.deleteSelections( row );
              tableModel.fireTableStructureChanged();
              tableModel.fireTableRowsDeleted(0,table.getRowCount());
              //table.getModel().fireTableChanged(new TableModelEvent(table.getModel()));
    private void upDateTable(JTable table)
    if((table.getSelectedColumn() == 0) && ((table.getColumnName(0)).equals(columnNames[0])))
         dirNameHold =(String) table.getValueAt(table.getSelectedRow(),table.getSelectedColumn());
                   File argument = findPath(dirNameHold);
                   if(argument.isFile())
                        CMRDialog.fileNameTextField.setText(argument.getName());
                        try
                             fullPath = argument.getCanonicalPath();                          
                             selectedFilename = argument.getCanonicalFile();                          
    CMRDialog.filtersComboBox.removeAllItems();
                             extension = fullPath.substring(fullPath.lastIndexOf('.'));
                             CMRDialog.filtersComboBox.addItem("( " + extension + " )" + " File");
                        catch(IOException e)
                             System.out.println("THE ERROR IS " + e);
                        return;
                   else if(argument.isDirectory())
                        String path = argument.getName();
                             //find the system dependent file separator
                             //String fileSeparator = System.getProperty("file.separator");
                        CMRDialog.driveComboBox.addItem(" " + path);
              subDir = Search.subDirs(argument);
              /**TBD:- needs a method to convert the vector to an array and return the array */
              directoryArray = new File[subDir.size()];
                   int indexCount = 0;
                   /** TBD:- This is inefficient way of converting a vector to an array */               
                   Iterator e = subDir.iterator();               
                   while( e.hasNext() )
                        directoryArray[indexCount] = (File)e.next();
                        indexCount++;
              /** now calls this method and clears the previous data */
              clearTableData(table);     
                   (SimpleTable.hashTable).clear();
                   //data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
                   formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
                   for(int k = 0; k < directoryArray.length; k++)
                        if(directoryArray[k].isDirectory())
                             dateDirectory = directoryArray[k].lastModified();
                             dirDate = formatter.format(new java.util.Date(dateDirectory));
                             data.addElement( new MyObj( directoryArray[k].getName(), "", "File Folder", "" + dirDate ) );
                             (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);                    
                        else if(directoryArray[k].isFile())
                             dateDirectory = directoryArray[k].lastModified();
                             fileDate = formatter.format(new java.util.Date(dateDirectory));
                             totalLen = directoryArray[k].length();
                             longe = new Long(totalLen);
                             data.addElement( new MyObj( directoryArray[k].getName(), longe + " Bytes", "", "" + fileDate ) );
                             (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
              // tableModel.fireTableDataChanged();          
              // tableModel.fireTableRowsInserted(0,1);
              table.revalidate();
              table.validate();               
    class MyTableModel extends DefaultTableModel
              int totalRows;
              int totalCols;
              public MyTableModel()
                   super();
                   setColumnIdentifiers (columnNames);
                   this.totalRows = data.size();
                   this.totalCols = columnNames.length;
              // this will return the row count of your table
              public int getRowCount()
                   return totalRows;
              // this return the column count of your table
              public int getColumnCount()
                   return totalCols;
              // this return the data for each cell in your table
              public Object getValueAt(int row, int col)
                   MyObj obj = (MyObj)data.elementAt( row );
                   if( obj != null )
                        if( col == 0 ) return( obj.first );
                        else if( col == 1 ) return( obj.last );
                        else if( col == 2 ) return( obj.third );
                        else if( col == 3 ) return( obj.fourth );
                        else return( "" );
                   return "";
              // if you want your table to be editable then return true
              public boolean isCellEditable(int row, int col)
                   return false;
              // if your table is editable edit the data vector here and
              // call table.tableChanged(...)
              public void setValueAt(Object value, int row, int col)
              protected void deleteSelections (int rows)
                   try
                        removeRow(rows);
                   catch(ArrayIndexOutOfBoundsException e)
                        System.out.println("The error in the row index " + rows);
                   fireTableDataChanged() ;
    class MyObj
              String first;
              String last;
              String third;
              String fourth;
              public MyObj( String f, String l, String t, String fo )
                   this.first = f;
                   this.last = l;
                   this.third = t;
                   this.fourth = fo;
    #####################################

    The following code works fine but it doesn't show me the new updated date in my JTable. I tried to print the values that I am getting and it does give the values on the prompt but doesn't show me on the JTable only first two are shown and the rest of the table is filled with the same values. I don't know what's going on and am tired of this TableModel thing so pla. take a time to give me some suggestions. Thanks
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.text.SimpleDateFormat;
    import java.util.*;
    public class SimpleTable extends JPanel {
         /** Formats the date */
         protected SimpleDateFormat           formatter;
    /** two-dimensional array to hold the information for each column */
    protected Object                     data[][];
    /** variable to hold the date and time in a raw form for the directory*/
    protected long                          dateDirectory;
    /** holds the readable form converted date for the directories*/
    protected String                     dirDate;
    /** holds the readable form converted date for the files*/
    protected String                     fileDate;
    /** variable to hold the date and time in a raw form for the file*/
    protected long                          dateFile;
    /** holds the length of the file in bytes */
    protected long                         totalLen;
    /** convert the length to the wrapper class */
    protected Long                         longe;
    /** Vector to hold the sub directories */
    protected Vector                     subDir;
    /** holds the name of the selected directory */
    protected String                    dirNameHold;
    /** converting vector to an Array and store the values in this */
    protected File                     directoryArray[];
    /** hashtable to store the key-value pair */
    protected static Hashtable hashTable = new Hashtable();
    /** refer to the TableModel that is the default*/
    protected DefaultTableModel      model;
    /** stores the path of the selected file */
    protected static String               fullPath;
    /** stores the currently selected file */
    protected static File selectedFilename;
    /** stores the extension of the selected file */
    protected static String           extension;
    protected Vector                     m = new Vector(0,1);
    /** holds the names of the columns */
    protected final String columnNames[] = {"Name", "Size", "Type", "Modified"};
    public SimpleTable(File directoryArray[])
              this.setLayout(new BorderLayout());
              this.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
              (SimpleTable.hashTable).clear();
              data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
              formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
              for(int k = 0; k < directoryArray.length; k++)
                   if(directoryArray[k].isDirectory())
                        data[k][0] = directoryArray[k].getName();
                        data[k][2] = "File Folder";
                        dateDirectory = directoryArray[k].lastModified();
                        dirDate = formatter.format(new java.util.Date(dateDirectory));
                        data[k][3] = dirDate;
                        (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);                    
                   else if(directoryArray[k].isFile())
                        data[k][0] = directoryArray[k].getName();
                        totalLen = directoryArray[k].length();
                        longe = new Long(totalLen);
                        data[k][1] = longe + " Bytes";
                        dateFile = directoryArray[k].lastModified();
                        fileDate = formatter.format(new java.util.Date(dateFile));
                        data[k][3] = fileDate;
                        (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
    model = new DefaultTableModel();
    model.addTableModelListener( new TableModelListener(){
              public void tableChanged( javax.swing.event.TableModelEvent e )
                   System.out.println("************ I am inside the table changed method ********" );
              final JTable table = new JTable(model);
              table.getTableHeader().setReorderingAllowed(false);
              table.setRowSelectionAllowed(false);
              table.setBorder( BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
              table.setShowHorizontalLines(false);
              table.setShowVerticalLines(false);
              table.addMouseListener(new MouseAdapter()
    /* public void mousePressed(MouseEvent e)
    //System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
    /* if(e.getClickCount() >= 2 &&
    (table.getSelectedColumn() == 0) &&
    ((table.getColumnName(0)).equals(columnNames[0])))
         //System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
         upDateTable(table);
    public void mouseReleased(MouseEvent e)
    //System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
    /* if(e.getClickCount() >= 2 &&
    (table.getSelectedColumn() == 0) &&
    ((table.getColumnName(0)).equals(columnNames[0]))) */
         //System.out.println("The clicked component is " + table.rowAtPoint(e.getPoint()) + "AND the number of clicks is " + e.getClickCount());
         upDateTable(table);
              /** set the columns */
              for(int c = 0; c < columnNames.length; c++)
                   model.addColumn(columnNames[c]);
              /** set the rows */
              for(int r = 0; r < data.length; r++)
                   model.addRow(data[r]);
              DefaultTableCellRenderer D_headerRenderer = (DefaultTableCellRenderer ) table.getTableHeader().getDefaultRenderer();
              table.getColumnModel().getColumn(0).setHeaderRenderer(D_headerRenderer );
              ((DefaultTableCellRenderer)D_headerRenderer).setToolTipText("File and Folder in the Current Folder");
    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this window.
    this.add(scrollPane, BorderLayout.CENTER);
    * Returns the number of columns
    public int getColumnTotal()
         return columnNames.length;
    * Returns the number of rows
    public int getRowTotal(Object directoryArray[])
         return directoryArray.length;
    private void upDateTable(JTable table)
    if((table.getSelectedColumn() == 0) && ((table.getColumnName(0)).equals(columnNames[0])))
         dirNameHold =(String) table.getValueAt(table.getSelectedRow(),table.getSelectedColumn());
                   File argument = findPath(dirNameHold);
                   if(argument.isFile())
                        CMRDialog.fileNameTextField.setText(argument.getName());
                        try
                             fullPath = argument.getCanonicalPath();                          
                             selectedFilename = argument.getCanonicalFile();                          
    CMRDialog.filtersComboBox.removeAllItems();
                             extension = fullPath.substring(fullPath.lastIndexOf('.'));
                             CMRDialog.filtersComboBox.addItem("( " + extension + " )" + " File");
                        catch(IOException e)
                             System.out.println("THE ERROR IS " + e);
                        return;
                   else if(argument.isDirectory())
                        String path = argument.getName();
                             //find the system dependent file separator
                             //String fileSeparator = System.getProperty("file.separator");
                        CMRDialog.driveComboBox.addItem(" " + path);
              subDir = Search.subDirs(argument);
              /**TBD:- needs a method to convert the vector to an array and return the array */
              directoryArray = new File[subDir.size()];
                   int indexCount = 0;
                   /** TBD:- This is inefficient way of converting a vector to an array */               
                   Iterator e = subDir.iterator();               
                   while( e.hasNext() )
                        directoryArray[indexCount] = (File)e.next();
                        indexCount++;
              /** now calls this method and clears the previous data */
              clearTableData(table);     
                   (SimpleTable.hashTable).clear();
                   data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
                   formatter = new SimpleDateFormat("mm/dd/yyyy hh:mm aaa");
                   m.clear();
                   data = null;
                   data = new Object[this.getRowTotal(directoryArray)][this.getColumnTotal()];
                   for(int k = 0; k < directoryArray.length; k++)
                        if(directoryArray[k].isDirectory())
                        System.out.println("Inside the if part");
                             data[k][0] = directoryArray[k].getName();
                             table.setValueAt(directoryArray[k].getName(),k,0);
                             //model.fireTableCellUpdated(k,0);
                             data[k][2] = "File Folder";
                             table.setValueAt("File Folder",k,2);
                             //model.fireTableCellUpdated(k,2);
                             dateDirectory = directoryArray[k].lastModified();
                             dirDate = formatter.format(new java.util.Date(dateDirectory));
                             data[k][3] = dirDate;
                             table.setValueAt(dirDate,k,3);
                             //model.fireTableCellUpdated(k,3);
                             (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);
                             m.add(data);
                             model.addRow(m);
                             model.fireTableDataChanged();                              
                        else if(directoryArray[k].isFile())
                   System.out.println("******* Inside the else part *******");
                             data[k][0] = directoryArray[k].getName();
                   System.out.println("The Name is == " + data[k][0]);
                             table.setValueAt(directoryArray[k].getName(),k,0);
                   System.out.println("The table cell value of the name is == " + table.getValueAt(k,0));
                             //model.fireTableCellUpdated(k,0);
                             totalLen = directoryArray[k].length();
                             longe = new Long(totalLen);
                             data[k][1] = longe + " Bytes";
                   System.out.println("The length == " + data[k][1]);
                             table.setValueAt(longe + " Bytes",k,1);
                   System.out.println("The table cell value of the length is == " + table.getValueAt(k,1));
                             //model.fireTableCellUpdated(k,0);
                             dateFile = directoryArray[k].lastModified();
                             fileDate = formatter.format(new java.util.Date(dateFile));
                             data[k][3] = fileDate;
                   System.out.println("The modified date == " + data[k][3]);
                             table.setValueAt(fileDate,k,3);
                   System.out.println("The table cell value of the name is == " + table.getValueAt(k,3));
                             //model.fireTableCellUpdated(k,0);
                             (SimpleTable.hashTable).put(directoryArray[k].getName(), directoryArray[k]);                    }
                             m.add(data);
                             model.addRow(m);
                             model.fireTableDataChanged();     
              // model.fireTableDataChanged();          
              // model.fireTableRowsInserted(0,1);
              table.revalidate();
              table.validate();               
         else
    * Searches the Hashtable and returns the path of the folder or the value.
    public File findPath(String value)
         return (File)((SimpleTable.hashTable).get(value));
    * This clears the previous data in the JTable
    public void clearTableData(JTable table)
         for(int row = 0; row < table.getRowCount() ; row++)
                   for (int col = 0; col < table.getColumnCount() ; col++)
                        table.setValueAt(null, row , col);
              model.fireTableStructureChanged();
    ###

  • Inserting rows in table control(Module pool)!!

    Hi,
    Pls provide me with some code sample for inserting rows in a table control (module pool)...
    Regards
    Gunjan

    HI
    Y dont u create a TABLE CONTROL using wizard and copy the coding-
    TRY THIS-
    WHEN 'INSR'.                      "insert row
           PERFORM FCODE_INSERT_ROW USING    P_TC_NAME
                                             P_TABLE_NAME.
    FORM fcode_insert_row
                   USING    P_TC_NAME           TYPE DYNFNAM
                            P_TABLE_NAME             .
    &SPWIZARD: BEGIN OF LOCAL DATA----
       DATA L_LINES_NAME       LIKE FELD-NAME.
       DATA L_SELLINE          LIKE SY-STEPL.
       DATA L_LASTLINE         TYPE I.
       DATA L_LINE             TYPE I.
       DATA L_TABLE_NAME       LIKE FELD-NAME.
       FIELD-SYMBOLS <TC>                 TYPE CXTAB_CONTROL.
       FIELD-SYMBOLS <TABLE>              TYPE STANDARD TABLE.
       FIELD-SYMBOLS <LINES>              TYPE I.
    &SPWIZARD: END OF LOCAL DATA----
       ASSIGN (P_TC_NAME) TO <TC>.
    *&SPWIZARD: get the table, which belongs to the tc                     *
       CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body
       ASSIGN (L_TABLE_NAME) TO <TABLE>.                "not headerline
    *&SPWIZARD: get looplines of TableControl                              *
       CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_LINES_NAME.
       ASSIGN (L_LINES_NAME) TO <LINES>.
    *&SPWIZARD: get current line                                           *
       GET CURSOR LINE L_SELLINE.
       IF SY-SUBRC <> 0.                   " append line to table
         L_SELLINE = <TC>-LINES + 1.
    *&SPWIZARD: set top line                                               *
         IF L_SELLINE > <LINES>.
           <TC>-TOP_LINE = L_SELLINE - <LINES> + 1 .
         ELSE.
           <TC>-TOP_LINE = 1.
         ENDIF.
       ELSE.                               " insert line into table
         L_SELLINE = <TC>-TOP_LINE + L_SELLINE - 1.
         L_LASTLINE = <TC>-TOP_LINE + <LINES> - 1.
       ENDIF.
    *&SPWIZARD: set new cursor line                                        *
       L_LINE = L_SELLINE - <TC>-TOP_LINE + 1.
    *&SPWIZARD: insert initial line                                        *
       INSERT INITIAL LINE INTO <TABLE> INDEX L_SELLINE.
       <TC>-LINES = <TC>-LINES + 1.
    *&SPWIZARD: set cursor                                                 *
       SET CURSOR LINE L_LINE.
    ENDFORM.                              " FCODE_INSERT_ROW
    HOpe this helps u
    Regds,
    Seema.

  • Help in inserting rows into a table

    I have a table called acct_fact,
    I need to insert rows in the table using a script but the problem is there's a column called seq_nbr which has random seq nbr of 14character length like 'ZWX98MGD9MVAD6J','ZWX98MG67RVAD6J' etc.,
    While inserting rows I need to generate such seq_nbr for those columns and insert rows into the table, can I use any such mechanism in my insert query to insert such random nbr's while inserting rows into a table.
    If so please suggest me

    Hi Peter,
    Thankyou for the quick reply:)
    can you suggest me how to implement it here in my script snippet:
    while read var_acct_nbr
    do
    echo "update acct_attr set acct_attr_exp_dt ='$ExpDate' where Acct_Attr_Value_Text='15' and acct_attr_exp_dt is null and person_id='LDCarrBillAgrm' and acct_nbr='$var_acct_nbr' ;" >> ./$DirectoryName/SQLQuery_$TimeStamp.sql
    echo "insert into acct_fact values ('$var_acct_nbr','$ExpDate','$ExpTime','*seq_nbr*','N','ProjTereza','Remoção de acordo d; data de expiração: $ExpDate',null,'1','LDE',null);" >> ./$DirectoryName/SQLQuery_$TimeStamp.sql
    done < ./$DirectoryName/ExpireAccts_$TimeStamp.LOG
    the script takes each acct_nbr nbr form a input file and fires an insert statement.
    The one in bold is the column where such sequence need to be inserted.can you help me in implementing the way you suggested in my script i.e., insert statement
    Thanks in Advance:)
    Edited by: rkrish on Jun 27, 2012 3:04 AM

  • "Create Table from select Query" Vs "Insert into"

    Hi
    Schenaio:
    My Select Query returns more than 10 million records, these records needs to be inserted into another table.
    Approach 1:
    I created table called TABLE1, and inserted the records using INSERT statement as a batch (batch size is 5000).
    Approach 2:
    I create table like,
    CREATE TABLE TABLE1 AS <SELECT QUERY>
    Here Apporach-1 took almost 40 minutes to complete the insert but Approach-2 took only 6 minutes.
    If anybody knows why it is? And is there any way to improve the performance of Approach-1?.
    Thanks
    Nidhi

    Most "batch" methods execute the same query multiple times. Row filtering is done after the rows are fetched from the source. The process of fetching all the rows could be a FullTableScan.
    Therefore, a FullTableScan is executed for each batch of 5000 rows.
    However, your query and batch definitions may well be different. We haven't seen the query and the execution plan.
    Another point : How are you "filtering" the rows (i.e the second execution inserts rows 5001 to 10000 and does not attempt to reinsert rows 1 to 5000) ?
    What is the overhead imposed by the filter ? (does the third execution have to exclude rows 1 to 10000 and inserts rows 10001 to 15000 and so on)
    Hemant K Chitale

Maybe you are looking for