Insert Duplicate rows with difrent languages

Hello everybody,
I need your help in solving this query with the most performant way.
I have a table:
Create Table "POSITION" (
id  number,
TEXT varchar2(50),
Language Varchar2(1)
);insert statments
INSERT INTO POSITION
VALUES (1, 'Secretary', 'E');
INSERT INTO POSITION
VALUES (1, 'Secrétaire', 'F');
INSERT INTO POSITION
VALUES (1, 'Segretario', 'I');
INSERT INTO POSITION
VALUES (1, 'Secretario', 'S');
INSERT INTO POSITION
VALUES (2, 'Assistance', 'E');
INSERT INTO POSITION
VALUES (2, 'Ayuda', 'S');As you have seen the text changes in diffrent languages for the same id. for whatever reasons the data is in complete in all languages (some ids missing english some french and some italian). I need a query to insert the missing language(s) in my example above Id number 2 the language French and Italian is missing so the query should copy the record English instead but with Language = 'F' and one more time with language = 'I' and so on.
in addition the query should look first to copy English if it doesn't exist then French if not then Italian when more than language exists.
hope I make it clear. as i said this query should be performant also as the data size is big.
Thanks for your help

Hi,
Okay, I see my mistake now.
You can use MERGE like this:
MERGE INTO     position     dst
USING     (
          SELECT     p.id
          ,     FIRST_VALUE (p.text IGNORE NULLS)
                    OVER ( PARTITION BY  p.id
                           ORDER BY      l.ord_num
                           ROWS BETWEEN  UNBOUNDED PRECEDING
                                    AND          UNBOUNDED FOLLOWING
                         )     AS top_text
          ,     FIRST_VALUE (p.lsource_anguage IGNORE NULLS)
                    OVER ( PARTITION BY  p.id
                           ORDER BY      l.ord_num
                           ROWS BETWEEN  UNBOUNDED PRECEDING
                                    AND          UNBOUNDED FOLLOWING
                         )     AS source_language
          ,     l.language
          FROM           all_languages     l
          LEFT OUTER JOIN  position     p     PARTITION BY (p.id)
                                   ON  l.language     = p.language
     )               src
ON     (     src.id          = dst.id
     AND     src.language     = dst.language
WHEN NOT MATCHED THEN
INSERT     (dst.id, dst.text,     dst.language, dst.source_language)
VALUES     (src.id, src.top_text, src.language, src.source_language)
;Or you can use INSERT, like this:
INSERT INTO     position (id, text, language, source_language)
WITH     got_analytics     AS
     SELECT     p.id
     ,     p.text          AS orig_text
     ,     FIRST_VALUE (p.text IGNORE NULLS)
               OVER ( PARTITION BY  p.id
                      ORDER BY      l.ord_num
                      ROWS BETWEEN  UNBOUNDED PRECEDING
                               AND          UNBOUNDED FOLLOWING
                    )     AS top_text
     ,     l.language
     ,     FIRST_VALUE (p.source_language IGNORE NULLS)
               OVER ( PARTITION BY  p.id
                      ORDER BY      l.ord_num
                      ROWS BETWEEN  UNBOUNDED PRECEDING
                               AND          UNBOUNDED FOLLOWING
                    )     AS source_language
     FROM           all_languageS     l
     LEFT OUTER JOIN  position     p     PARTITION BY (p.id)
                              ON  l.language     = p.language
SELECT     id, top_text, language, source_language
FROM     got_analytics
WHERE     orig_text     IS NULL
;This is basically what I posted before, except that I added
...                      ROWS BETWEEN  UNBOUNDED PRECEDING
                               AND          UNBOUNDED FOLLOWINGto all the analytic clauses.
The problem was that when you say "ORDER BY ord_num", that creates a default window that includes only the current ord_num and lower values. We need to look at all values, lower and higher, so we have to override the default windowing.
Edited by: Frank Kulash on Feb 29, 2012 8:58 PM
Edited by: Frank Kulash on Mar 1, 2012 11:31 AM
Added correct MERGE statement.

Similar Messages

  • How to eliminate inserting  Duplicate rows into database using JDBC Adapter

    File->Xi->JDBC
    In above Scenario if the file has two rows their values are identical, then how can we eliminated inserting  Duplicate rows into database using JDBC Adapter

    Database is a consumer of a SERVICE (SOA!!!!!!).
    Database plays a business system role here!!!!
    Mapping is part of an ESB service
    Adaptor is a technology adapted to ESB framework to support specific protocol.
    ESB accomplish ESB duties such as transformation, translation, routing. Routing use a protocol accepted by the consumer. In a JDBC consumer it is JDBC protocol and hence it a JDBC adaptor.
    There is clear separation on responsibilities among business system and ESB. ESB do not participate in business decision or try to get into business system data layer.
    So who ever are asking people to check duplicate check as part of mapping (an ESB service) may not understand integration practice.
    Please use an adaptor module which will execute the duplicate check with business system in a plug and play approach and separate that from ESB service so that people can build integration using AGILE approach.
    Thanks

  • Insert one row with FileInputStream bigger than 30M always OutOfMemoryError

    Hi,somebody can help me to solve my problem as follow:
    The following file 'insertTest.jsp' run with Tomcat-5.0.18 and MySQL-4.0.17.
    If I insert a row with a file bigger then 30M,I always get OutOfMemoryError messages shown as next.
    In fact , I have adjusted variables as:
    set-variable = max_allowed_packet=100M
    set-variable = max_heap_table_size=100M
    set-variable = tmp_table_size=100M
    set-variable = key_buffer_size=100M
    set-variable = innodb_buffer_pool_size=100M
    set-variable = max_connections=200
    set-variable = bulk_insert_buffer_size=100M
    set-variable = sort_buffer_size=100M
    set-variable = myisam_sort_buffer_size=100M
    'insertTest.jsp' :
    <%@ page language="java" contentType="text/html;charset=Big5" errorPage="" %>
    <%@ page import="java.sql.*,java.io.*" %>
    <%
    Connection conn = null;
    java.sql.Statement stmt = null;
    String tableName="goodtable";
    boolean tableNameExist=false;
    String createtable = "Create table "+tableName+" (sn INT AUTO_INCREMENT NOT NULL PRIMARY KEY ,fileImage longblob)";
    Class.forName("com.mysql.jdbc.Driver");
    conn =DriverManager.getConnection("jdbc:mysql://thisIpAddress/thisDatabaseName?user=thisUser&password=thisPsw");
    try {
    DatabaseMetaData dbmd = conn.getMetaData();
    String[] types = {"TABLE"};
    ResultSet resultSet = dbmd.getTables(null, null, "%", types);
    while (resultSet.next()) {
    String tName = resultSet.getString(3);
    if(tName.equals(tableName)){
    tableNameExist=true;
    break;
    String tableCatalog = resultSet.getString(1);
    String tableSchema = resultSet.getString(2);
    catch (SQLException e) {}
    out.print("<html><body bgcolor='#669999'>");
    if(!tableNameExist){
    stmt = conn.createStatement();
    stmt.execute(createtable);
    out.print("<p>&#12288;<p><center>CreateTable="+tableName+" Ok!<hr>");
    else
    out.print("<p>&#12288;<p><center>' "+tableName+" ' already exist!<hr>");
    //The test file(at C:\fileSize30M.zip) is put here.
    File file = new File("C:\\fileSize30M.zip");
    FileInputStream fis = new FileInputStream(file);
    String qry="Insert into "+tableName+"(fileImage) values(?)";
    java.sql.PreparedStatement pstmt=conn.prepareStatement(qry);
    pstmt.setBinaryStream(1,fis,fis.available());
    out.print("'before pstmt.executeUpdate()' is ok<p>");
    System.out.println("'before pstmt.executeUpdate()' is ok<p>");
    int ok=pstmt.executeUpdate();
    if(ok==1){
    out.print("'after pstmt.executeUpdate()' is ok");
    System.out.println("'after pstmt.executeUpdate()' is ok<p>");
    fis.close();
    pstmt.close();
    conn.close();
    out.print("</body></html>");
    %>
    type: Exception report
    description: The server encountered an internal error () that prevented it from fulfilling this request.
    exception :
    javax.servlet.ServletException
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
    org.apache.jsp.insertTest_jsp._jspService(insertTest_jsp.java:101)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    root cause :
    java.lang.OutOfMemoryError

    Increase you heap size on Tomcat startup. I haven't used Tomcat in some years but I think you can just set a JAVA_OPTS environment variable with the text Xmx128M and your problems will go away. I'm thinking this is an issue because I'm assuming you are running Tomcat on a Windows box where the default heap for Java is relatively small like 32M or 64M or something like that.
    Cliff

  • Insert multiple rows with autoincrement id

    I need to insert multiple rows to a table which has an autoincrement PK (unique), e.g:
    Entity:
    public Class Entity{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    Private Long id;
    Facade:
    @PersistenceContext(unitName = "xx-enterprise-ejbPU")
    protected EntityManager em;
    public void create(Entity entity) {
    em.persist(entity);
    Service Class:
    public Class Service implements ServiceLocal{
    @EJB
    private XxxFacadeLocal xxxFacade;
    public void saveEntity(Entity entity){
    xxxFacade.create(entity)
    ManageBean:
    public Class ManageBean
    @EJB
    private ServiceLocal service;
    public void doSave(ActionEvent event)
    service.saveEntity(entity1); //entity.id is set to null, suppose to be generated by DB auto_increment, i.e. insert 3 rows with 3 different ids
    service.saveEntity(entity2);
    service.saveEntity(entity3);
    The result is: Key duplication error on inserting entity2, but entity1 is inserted into DB with id auto increased correctly.
    If I insert only one row each time for test purpose, everything works as expected.
    But what I need is to insert multiple rows. How to do it?
    Thank you in advance.

    Like this (although the @Basic annotation is very much unnecessary). So if it isn't happening you must have made a mistake somewhere. Are you sure the ID column actually has auto_increment?
    Also if you are using Hibernate as the persistence provider and you put it on the classpath, check the packages of the annotations you are using; Hibernate and JPA share some with the same name unfortunately.

  • Merge inserting duplicate rows

    Hi,
    I first check if a particular dept_no exists in the table, if not insert into the table. I am getting duplicate rows inserted.
    This is the table data before Merge.
       CUST_ID FIRST_NAME           LAST_NAME               DEPT_NO     SALARY
             1 Dan                  Morgan                       10     100000
             2 Jack                 Cline                        20     100000
             3 Helen                Lofstrom                     20      50000This is the table data after Merge.
    3 rows merged.
       CUST_ID FIRST_NAME           LAST_NAME               DEPT_NO     SALARY
             1 Dan                  Morgan                       10     100000
             2 Jack                 Cline                        20     100000
             3 Helen                Lofstrom                     20      50000
             4 Ram                  Bharad                       30       2000
             4 Ram                  Bharad                       30       2000
             4 Ram                  Bharad                       30       2000
    6 rows selected.This is the code to merge
    MERGE INTO customer c
    USING ( SELECT cust_id,
                   first_name,
                   last_name,
                   dept_no,
                   salary
            FROM customer ) e
    ON ( c.dept_no = 30 )
    WHEN MATCHED THEN
        UPDATE SET
               c.cust_id    = 4,
               c.first_name = 'Ram',
               c.last_name  = 'Bharad',
               c.salary     = 2000
    WHEN NOT MATCHED THEN
        INSERT
        (c.cust_id,c.first_name, c.last_name,c.dept_no,c.salary)
        VALUES
        (4,'Ram','Bharad',30,2000);Shouldn't the above code insert once, and update twice?
    Thanks

    You have done it wrong...
    Try like this
    SQL> create table customer(cust_id number,first_name varchar2(20), last_name varchar2(20), dept_no number, salary number)
      2  /
    Table created.
    SQL> insert into customer
      2  select 1, 'Dan','Morgan',10,100000 from dual
      3  union all
      4  select 2, 'Jack','Cline',20,100000 from dual
      5  union all
      6  select 3, 'Helen','Lofstrom',20,50000 from dual
      7  /
    3 rows created.
    SQL> commit
      2  /
    Commit complete.
    SQL> select * from customer
      2  /
       CUST_ID FIRST_NAME           LAST_NAME               DEPT_NO     SALARY
             1 Dan                  Morgan                       10     100000
             2 Jack                 Cline                        20     100000
             3 Helen                Lofstrom                     20      50000
    SQL> MERGE INTO customer c
      2  USING ( SELECT 4 cust_id,
      3                 'Ram' first_name,
      4                 'Bharad' last_name,
      5                 30 dept_no,
      6                 2000 salary
      7          FROM dual ) e
      8  ON ( c.dept_no = e.dept_no )
      9  WHEN MATCHED THEN
    10      UPDATE SET
    11             c.cust_id    = e.cust_id,
    12             c.first_name = e.first_name,
    13             c.last_name  = e.last_name,
    14             c.salary     = e.salary
    15  WHEN NOT MATCHED THEN
    16      INSERT
    17      (c.cust_id,c.first_name, c.last_name,c.dept_no,c.salary)
    18      VALUES
    19      (e.cust_id,e.first_name, e.last_name,e.dept_no,e.salary);
    1 row merged.
    SQL> select * from customer
      2  /
       CUST_ID FIRST_NAME           LAST_NAME               DEPT_NO     SALARY
             1 Dan                  Morgan                       10     100000
             2 Jack                 Cline                        20     100000
             3 Helen                Lofstrom                     20      50000
             4 Ram                  Bharad                       30       2000but beware of the fact that you are joining based on dept_no so multiple rows can get updated with same cust_id. see below.
    SQL> rollback
      2  /
    Rollback complete.
    SQL>  MERGE INTO customer c
      2   USING ( SELECT 4 cust_id,
      3             'Ram' first_name,
      4             'Bharad' last_name,
      5             20 dept_no,
      6             2000 salary
      7      FROM dual ) e
      8   ON ( c.dept_no = e.dept_no )
      9   WHEN MATCHED THEN
    10       UPDATE SET
    11         c.cust_id    = e.cust_id,
    12         c.first_name = e.first_name,
    13         c.last_name  = e.last_name,
    14         c.salary     = e.salary
    15   WHEN NOT MATCHED THEN
    16       INSERT
    17       (c.cust_id,c.first_name, c.last_name,c.dept_no,c.salary)
    18       VALUES
    19       (e.cust_id,e.first_name, e.last_name,e.dept_no,e.salary);
    2 rows merged.
    SQL> select * from customer
      2  /
       CUST_ID FIRST_NAME           LAST_NAME               DEPT_NO     SALARY
             1 Dan                  Morgan                       10     100000
             4 Ram                  Bharad                       20       2000
             4 Ram                  Bharad                       20       2000Thanks,
    Karthick.

  • Inserting multiple rows with single insert statement ?

    Hi ,,
    Consider a PL/SQL procedure.
    I want to pass an array of values and insert in a table with a single statement.
    Moreover I want to call this procedure to insert multiple rows from OCI program.
    Can some body help ? :(
    Thanks
    Chandu

    Hi Vincent,
    Regular array insert which you have mentioned works in case of insert statement(This is to eliminate multiple calls to server)
    Will it work for passing array to Stored procedure, in this case procedure will be called only once with an array.
    It will be of great help if you give an example.
    Thanks
    Chandra

  • Table maint genertr inserting multiple rows with all fields editable

    Hi
    I have created a ztable in se11 and maintained table maintenance generator SM30.
    Now i need to insert multiple rows into the table with all fields editable.
    How can i achieve this?
    Thanks in advance.

    >
    deepak thimmegowda wrote:
    > Hi
    >
    > I have created a ztable in se11 and maintained table maintenance generator SM30.
    >
    > Now i need to insert multiple rows into the table with all fields editable.
    >
    > How can i achieve this?
    >
    > Thanks in advance.
    Create a Table maintenance generator with One Step .
    regards,
    Jinson.

  • Identify newly inserted duplicate row

    Hi,
    I have an issue. I want to identify the newly inserted duplicate record in the table. But the problem is the old record is having a rowid greater than the one for the newly inserted duplicate record. How this can happen?
    Has anyone faced such problem? Please let me know.
    Urgent.
    Thanks & Regds,
    Nandakumar

    Mark, I might disagree with that. Just because the fields that make up a unique constraint are duplicates doesn't make the records identical in all fields. Take for example four entries in the Social Security database with my social security number. One would be for Rory, another for Jose, third for Manual and the fourth for Juan. Four records with 3 violating a unique constraint, but the records aren't identical.
    First thing to do is put a unique constraint on the table to prevent duplicate key entries.

  • 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();
    ###

  • JDev 9i RC2 Failure when trying to insert a row with DATATAGS

    500 Internal Server Error
    oracle.jbo.JboException: Need the datasource property defined if not used
    within a DefinitionIterate, a RowSetIterator or a Row tag
    This is the error message occuring when i do the following
    I was trying to insert a record via DataTags (JBO Datatags in JDeveloper 9i
    Release Candidate 2).
    The following should show you the details
    <body bgcolor=#CCCCCC>
    <br>
    <%@ taglib uri="/webapp/DataTags.tld" prefix="jbo" %>
    <br>
    <jbo:ApplicationModule id="am"
    configname="PrevDoc.PrevDocModule.PrevDocModuleLocal" username="zode"
    password="zode"/>
    <br>
    <jbo:DataSource id="ds" appid="am" viewobject="MicEindocView">
    </jbo:DataSource>
    <br>
    <center>
    <p><b>MicEindocView Search Results</b></p>
    <br>
    <jbo:Row id="newRow" datasource="ds" action="Create" />
    <jbo:SetAttribute dataitem="Efdsid" value="9999" />
    <jbo:SetAttribute dataitem="Efdmandant" value="55" />
    <jbo:SetAttribute dataitem="Efdwerk" value="00" />
    <jbo:SetAttribute dataitem="Efdperiode" value='200204' />
    <jbo:SetAttribute dataitem="Efdvssart" value='AWB' />
    <jbo:SetAttribute dataitem="Efdvssnr" value='TEST WEB JODE' />
    </jbo:Row>
    <jbo:Commit appid="am" />
    <jbo:ReleasePageResources releasemode="Stateless"/>
    </center>
    </body>
    </html>
    These fields are not null fields in the database. At least this fields must be
    entered.
    Can you please tell me the reason why the above error occurs at any time??
    Thanks
    I appreciate all your help on this issue.
    Thanks a lot

    Josef,
    Remove the closing slash in this tag.
    <jbo:Row id="newRow" datasource="ds" action="Create" />
    I am sure you meant to close it with the </jbo:Row> some lines below.
    That explain the complaint of the setAttributeTag missing their context.
    Charles.

  • Update/Insert Duplicate Rows

    Hi I am loading a target table [empty] for the first time. I am using update/insert strategy. however, it's only inserting. not updating inserted rows.

    In a single mapping and on an empty table you can only insert rows. The Insert/Update strategy will update rows if the matching criteria you have used satisfies on an existing set of rows prior to your running the mapping. In other words you cannot expect OWB to update rows which it has inserted in the same statement !...
    You can try Row Based mode and put an order by clause before inserting into the target table and check to see if the update happens.
    Regards
    -AP

  • Insert multiple rows with one sql statement in access

    Hi,
    I'm trying to copy a table into another. What I want to do is to use "Insert into table1 select * from table2 where field > val". Something like that. I know a lot of databases support it. I was wondering if ms access ODBC driver also supports it. I searched quite a bit and haven't found a definitive answer on this.
    Thank you

    Yes, M$ Access 2000 supports it. This is from their help:
    INSERT INTO Statement
    Adds a record or multiple records to a table. This is referred to as an append query.
    Syntax
    Multiple-record append query:
    INSERT INTO target [(field1[, field2[, ...]])] [IN externaldatabase]
    SELECT [source.]field1[, field2[, ...]
    FROM tableexpression
    Single-record append query:
    INSERT INTO target [(field1[, field2[, ...]])]
    VALUES (value1[, value2[, ...])
    The way you've written the INSERT, table1 and table2 have to have the same # of columns and the same types, of course.

  • Inserting multiple rows with 1 value of sequence

    hi
    need help again for my same school project
    i need to insert the very 1 same value of a value which i get from a sequence/autocount(think of the situation like a point-of-sales where there is only 1 transaction no. for multiple items and not 1 for every single item sold)
    eg. nextval generated by sequence is 2
    transaction_no---item
    2----------------01
    2----------------02
    2----------------03
    and so on
    i know i can't do it by seq_name.nextval because it will increment by 1 which i stated to increment by in d sequence
    thank you!!!

    you may try this:
    First -- select seq_name.nextval from dual
    Save it into some variable and the use in your inserts

  • Query to insert a row in a table with same values except 1 field.

    Suppose I have a table with 100 columns(fields).
    I want to insert a row with 99 fileds being the same as previous ones except one fileld being different.
    The table doesn't have any constraints.
    Kindly suggest a query to solve the above purpose..

    And for much more lazy people, a desc of table is shorter to write. :-)
    Then copy & paste into any editor, then mode column to add a comma after every column name in one shot.Or have the system do it for you. Be lazy.
    SELECT Column_Name || ',' FROM User_Tab_Columns where Table_Name = '';
    Indeed, it can be converted to a script called desc(.sql)
    SELECT Column_Name || ',' FROM User_Tab_Columns where Table_Name = '&1' ORDER BY Column_Id;
    Then desc or @desc.

  • How to update duplicate row from table

    Hi,
    how to update duplicate row from table?
    First to find duplicate row then update duplicate row with no to that duplicate row in oracle.
    can you give me suggestion on it?
    Thanks in advance.
    your early response is appreciated...

    In order to find a duplicate row, see:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1224636375004
    (or search this forum, your question has been asked before)
    In order to update it, just create and use an Oracle sequence, have it start and increment at a value that doesn't exist in your table.
    If that doesn't get you going, post some CREATE TABLE + INSERT INTO statements, and the results you want from them, in other words: a complete testcase.

Maybe you are looking for

  • Best ways to view/display PDF/Excel files stored in the Database

    What are best ways to display/view PDF/Excel files stored in the Database? thanks L

  • Returning a ref cursor on a Global Temporary table

    I realize this is probably not feasible but I am manipulating data and storing it in a GTT and I wish to return that transformed data out as a ref cursor is this possible to do? I also dont want a static table because this is a heavily hit procedure

  • Compiling and Bytecode

    If this post sounds messed up, that's because it likely is. You're gonna have to work with me on this one... If you compile a class that has dependencies on at least one more class, that other class must be present (either as source code or bytecode)

  • Query for SP to make a udf field mandatory

    Hi, I got a UDF with name (Received By) in Header of GRPO document if the user does not fill the field the document should not be added. I know this is possible by SP but can any one give me the query for it. I searched i got certain query but i dont

  • Network Monitor and WebServices

    Hi all, my project uses a WebService by means of classes generated by the introspection service in Flash Builder 4. The service is located in a external server, and functions correctly when debugging locally my project, but only if Network Monitor is