Plz rescue me from delete prob of table sorting

i have a JTable referneced to SortableTableModel which is a seperate class and extended to DefaultTableModel, this jtable has diff classes of TableSorter.
in main panel program sorting works find but when I delete a record it doesnt work and delete the wrong row frm the view and i tried many ways to fix it...please help me if you know who has sorting classes working fine somewhere plz send me the sources...thanks...
my email is [email protected]
here is the part where i am deleting the row in my panel, as you can see i tried diff things to fix ...nothing worked..:(
JOptionPane.showConfirmDialog(null,
int deletedRow = abcTable.getSelectedRow();
tableModel.removeRow(deletedRow);
//abcTable.tableChanged(new TableModelEvent(tableModel));
tableModel.fireTableRowsDeleted(deletedRow,deletedRow);
//tableModel.sortByColumn(sortCol, isAscent);
//tableModel.fireTableDataChanged();
((SortableTableModel)header.getTable().getModel()).sortByColumn(sortCol, isAscent);
//abcTable.revalidate();
// ((SortableTableModel)header.getTable().getModel()).sortByColumn(sortCol, isAscent);
//tableModel.indexes = tableModel.getIndexes();
//abcTable.repaint();
// tableModel.fireTableRowsDeleted(deletedRow,deletedRow);
// update indexes with removed row
// tableModel.indexes = tableModel.removeIndexfromIndexes(deletedRow);
// ((SortableTableModel)header.getTable().getModel()).sortByColumn(sortCol, isAscent);
//tableModel.indexes = tableModel.getIndexes();
//tableModel.removeRow(sorter.convertSortedRowIndexToModel(abcTable.getSelectedRow()));
//=====------------------
plz try rescue me
THANKS
amir

If you are using the TableSorter downloaded from SUN, then you might have problem deleting row from the table once it's sorted.
Here is my solution:
Step 1:
Add the following method to TableSorter class.
public int getTranslatedIndex(int sortedIndex)
    checkModel();
    return indexes[sortedIndex];
}Step 2:
The row index you get from the Table does not reflect the real index once the table has been sorted. You will need to tranlate the row index in order to find the real row index in your table modle.
int row = Table.getSelectedRow();
int realRow = TableSorter.getTranslatedIndex(row);
TableModel.removeRow(realRow);Good Luck :)

Similar Messages

  • Plz rescue me from delete prob of sorting jtable

    i have a JTable referneced to SortableTableModel which is a seperate class and extended to DefaultTableModel, this jtable has diff classes of TableSorter.
    in main panel program sorting works find but when I delete a record it doesnt work and delete the wrong row frm the view and i tried many ways to fix it...please help me if you know who has sorting classes working fine somewhere plz send me the sources...thanks...
    my email is [email protected]
    here is the part where i am deleting the row in my panel, as you can see i tried diff things to fix ...nothing worked..:(
    JOptionPane.showConfirmDialog(null,
    int deletedRow = abcTable.getSelectedRow();
    tableModel.removeRow(deletedRow);
    //abcTable.tableChanged(new TableModelEvent(tableModel));
    tableModel.fireTableRowsDeleted(deletedRow,deletedRow);
    //tableModel.sortByColumn(sortCol, isAscent);
    //tableModel.fireTableDataChanged();
    ((SortableTableModel)header.getTable().getModel()).sortByColumn(sortCol, isAscent);
    //abcTable.revalidate();
    // ((SortableTableModel)header.getTable().getModel()).sortByColumn(sortCol, isAscent);
    //tableModel.indexes = tableModel.getIndexes();
    //abcTable.repaint();
    // tableModel.fireTableRowsDeleted(deletedRow,deletedRow);
    // update indexes with removed row
    // tableModel.indexes = tableModel.removeIndexfromIndexes(deletedRow);
    // ((SortableTableModel)header.getTable().getModel()).sortByColumn(sortCol, isAscent);
    //tableModel.indexes = tableModel.getIndexes();
    //tableModel.removeRow(sorter.convertSortedRowIndexToModel(abcTable.getSelectedRow()));
    //=====------------------
    plz try rescue me
    THANKS
    amir

    Hi!
    The data is sorted in the tableSorter class and not in the tableModel class. Change your code like this and check
    Add this method to your tableSorter class:
         public int convertToSortedRow(int i) {
              if (indexes!=null) return indexes(i);
              return i;
    And during deleting use:
    //row in sorted view
    int deletedRow = abcTable.getSelectedRow();
    // actual row in data model
    int actualRow = sorterObj.convertToSortedRow(deletedRow);
    tableModel.removeRow(actualRow);

  • How to restrict the user(Schema) from deleting the data from a table

    Hi All,
    I have scenario here.
    I want to know how to restrict a user(Schema) from deleting the values from a table created in the same schema.
    Below is the example.
    I have created a table employee in abc schema which has two values.
    EMPLOYEE
    ABC
    XYZ
    In the above scenario the abc user can only fire select query on the EMPLOYEE table.
    SELECT * FROM EMPLOYEE;
    He should not be able to use any other DML commands on that table.
    If he uses then Insufficient privileges error should be thrown.
    Can anyone please help me out on this.

    Hi,
    kumar0828 wrote:
    Hi Frank,
    Thanks for the reply.
    Can you please elaborate on how to add policies for a table for just firing a select DML statement on table.See the SQL Packages and Types manual first. It has examples. You can also search the web for examples. This is sometimes called "Virtual Private Database" or VPD.
    If you have problems, post a specific question here. Include CREATE TABLE and INSERT statements to create a table as it exists before the policies go into effect, the PL/SQL code to create the policies, and additonal DML statements that will be affected by the policies. Show what the table should contain after each of those DML statements.
    Always say which version of Oracle you're using. Confirm that you have Enterprise Edition.
    See the forum FAQ {message:id=9360002}
    The basic idea behind row-level security is that it generates a string that is automatically added to SELECT and/or DML statement WHERE clauses. For example, if user ABC is only allowed to query a table on Sunday, then you might write a function that returns the string
    USER  != 'ABC'
    OR      TO_CHAR (SYSDATE, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH') = 'SUN'So whenever any user says
    SELECT  *
    FROM    table_x
    ;what actually runs is:
    SELECT  *
    FROM    table_x
    WHERE   USER  != 'ABC'
    OR      TO_CHAR (SYSDATE, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH') = 'SUN'
    ;If you want to prevent any user from deleting rows, then the policy function can return just this string
    0 = 1Then, if somone says
    DELETE  employee
    ;what actually gets run is
    DELETE  employee
    WHERE   0 = 1
    ;No error will be raised, but no rows will be deleted.
    Once again, it would be simpler, more efficient, more robust and easier to maintain if you just created the table in a different schema, and not give DELETE privileges.
    Edited by: Frank Kulash on Nov 2, 2012 10:26 AM
    I just saw the previous response, which makes some additional good points (e.g., a user can always TRUNCATE his own tables). ALso, if user ABC applies a security policy to the table, then user ABC can also remove the policy, so if you really want to prevent user ABC from deleting rows, no matter how hard the user tries, then you need to create the policies in a different schema. If you're creating things in a different schema, then you might as well create the table in a different schema.

  • Program or Function module to delete data from Open Hub Destination Table

    Hi All,
    Can anybody suggest me a Program or Function module to delete data from Open Hub Destination Table.
    Thanks & Regards,
    Vinay Kumar

    You can simply goto t-code SE14 mention the open hub destination table and Delete data by clicking on "Activate and Adjust database" with radio button "Delete Data".
    Regards,
    Arminder

  • How to delete contents from more than 1 table

    How to delete the entire contents from more than 1 table in a single query.
    It is very urgent,
    Thanks in advance
    John

    Goto SE11 ->Open table ->Utility ->data base utility ->delete database table.
    BTW, Do not do it.
    Thanks,
    Ashish

  • How to prevent record from setup table from deletion if it is used in atabl

    i have two table setup table and master table
    the setup table contains data from countries and i use this countries in master table
    i want to prevenet a user from deleting country if it is used in master table
    i know i can do this if i make a foreing key in setup table
    but in this cases the exception message are raised from the data base
    can i make this from the jdeveloper by asscociation and view object and customise the message that are raised to the user
    thanks in advance

    The question is why to program this yourself if it's available by the framework?
    You can customize the error message raised by the db in the framework (there is a whole chapter in the docs).
    Timo

  • Delete From More than 1 table without using execute immediate

    Hi,
    Am new to PL/SQL, I had been asked to delete few of the table for my ETL jobs in Oracle 10G R2. I have to delete(truncate) few tables and the table names are in another table with a flag to delete it or not. So, when ever I run the job it should check for the flag and for those flag which is 'Y' then for all those tables should be deleted without using the Execute Immediate, because I dont have privilages to use "Execute Immediate" statement.
    Can anyone help me in how to do this.
    Regards
    Senthil

    Then tell you DBA's, or better yet their boss, that they need some additional training in how Oracle actually works.
    Yes, dynamic sql can be a bad thing when it is used to generate hundreds of identical queries that differ ony in the literals used in predicates, but for something like a set of delte table statements or truncate table statements, dynamic sql is no different in terms of the effect on the shared pool that hard coding the sql statements.
    This is a bad use of dynamic sql, because it generates a lot of nearly identical statements due to the lack of bind variables. It is the type of thing your DBA's should, correctly, bring out the lead pipe for.
    DECLARE
       l_sql VARCHAR2(4000);
    BEGIN
       FOR r in (SELECT account_no FROM accounts_to_delete) LOOP
          l_sql := 'DELETE FROM accounts WHERE account_no = '||r.account_no;
          EXECUTE IMMEDIATE l_sql;
       END LOOP;
    END;This will result in one sql statement in the shared pool for every row in accounts_to_delete. Although there is much else wrong with this example, from the bind variable perspective it should be re-written to use bind variables like:
    DECLARE
       l_sql  VARCHAR2(4000);
       l_acct NUMBER;
    BEGIN
       FOR r in (SELECT account_no FROM accounts_to_delete) LOOP
          l_sql := 'DELETE FROM accounts WHERE account_no = :b1';
          EXECUTE IMMEDIATE l_sql USING l_acct;
       END LOOP;
    END;However, since you cannot bind object names into sql statements, the difference in terms of the number of statements that end up in the shared pool between this:
    DECLARE
       l_sql VARCHAR2(4000);
    BEGIN
       FOR r in (SELECT table_name, delete_tab, trunc_tab
                 FROM tables_to_delete) LOOP
          IF r.delete_tab = 'Y' THEN
             l_sql := 'DELETE FROM '||r.table_name;
          ELSIF r.trunc_tab = 'Y' THEN
             l_sql := 'TRUNCATE TABLE '||r.table_name;
          ELSE
             l_sql := NULL;
          END IF;
          EXECUTE IMMEDIATE l_sql;
       END LOOP;
    END;and something like this:
    BEGIN
       DELETE FROM tab1;
       DELETE FROM tab2;
       EXECUTE IMMEDIATE 'TRUNCTE TABLE tab3';
    END;or this as a sql script
    DELETE FROM tab1;
    DELETE FROM tab2;
    TRUNCTE TABLE tab3;is absolutley nothing.
    Note that if you are truncating some of the tables, and wnat/need to use a stored procedure, you are going to have to use dynamic sql for the truncates anyway since trncate is ddl, and you cannot do ddl in pl/sql wiothout using dynamic sql.
    John

  • How shall I delete the data from R/3 setup tables

    Hi Experts,
    How shall I delete the data from R/3 setup tables
    Regards
    Sailekha

    Hi Sailekha , to delete the set up table in r/3 either u can go to tcode LBWG as already mentioned or u can also delete the same from tcode SBIW
    Settings for Application-Specific DataSources (PI)  -
    Logistics -
    Managing Extract Structures -
    Initialization -
    Delete the Contents of the Setup Tables .
    Just click the clock there then u hace toi juct give the application component name like for Inventory 3 , then execute it , it will delete the set up table for inventory ..
    Regards..

  • Prevent user from deleting rows from all tables in his own schema

    Hi,
    How can I prevent user from deleting rows in all tables in his own schema.
    I want the user to not able to delete rows from any existing or new tables that might be added in the future.
    The user does not have the "DELETE ANY TABLE" system privilege.
    Please advise.
    Thanks.

    Nowadays, I'd also avoid triggers (if possible).
    Sometimes, when I daydream, I'm rewriting a few applications that I've contributed to as a newbie, and I'm very ashamed of it nowadays.
    From what I've experienced, in retrospective, the emphasis on teaching 'Oracle stuff' has been lying far too much on PL/SQL row-by-row oriented processing instead of letting Oracle 'crunch' sets at once.
    Most of my debugging hours ended up in discovering one or more database triggers 'doing stuff automagically'.
    Another nice blogpost: http://rwijk.blogspot.com/2007/09/database-triggers-are-evil.html
    Regarding OP's question:
    I would just rethink/reconsider this requirement completely.
    Correctly implementing privileges and roles seems the best way to go, yes.
    Triggers? Nah...
    pre-post-edit, noticed thread got updated just before posting
    Don't know what you mean with 'namedropping', but I think it's legitimate to point other readers to interesting Oracle related opinions/articles that do have a technical background and lots of interesting examples.
    post dreaded OTN outage edit (from here)
    Again: I would just rethink/reconsider this requirement completely.
    Both trigger/vpd are being used to hide a design flaw here.

  • Unable to delete period from Periods in Control tables

    I am trying to delete period 'Sep' from Periods in Control Tables.
    But getting msg as 'FDM was unable to find the Record to delete'.
    Not sure whether the record got deleted internally.But I can still see it in my Period list in Control tables.
    Cud anyone suggest how shud I delete period from Control tables and where these periods are stored internally in FDM??
    Waiting for Reply!!!!!!

    Hi,
    There is also a note in Metalink which suggests the record be deleted from workbench client. I did that and it worked. The cause is stated as the record not being entered correctly, and hence the application is unable to find it.
    Thanks
    Ramya

  • Unable to update and delete record in table

    Hello All,
    Kindly help me regarding the below mentioned issue plz
    When I want to update or delete record in table from form developed in 6i give no error message but no action and when I run same form on other system updation and deletion are successfully done.
    Any suggestion

    Hello
    More explanation is as under:
    1. I am working on only one table say A
    2. Wants to update only one row of Table A at one time in single user envoirment.
    3. My form is successfully update some rows as well but not on all rows on one PC while same form able to update all rows on other PC.
    4. I drop the table and re-create the table again but problem persist.
    Any advice plz.

  • What is the use of delet set up table in lo **** pit, exactly what happenda

    what is the use of delete set up table in lo **** pit, exactly what happened if we do the process, is all tables will lose their data which r available in functional module,
    Why i'm asking this, because we assign functional module in LBWG.
    plz .......
    thanx
    vidhu

    HI Vidhu,
    Initially we don't delete the setup tables but when we do change in extract structure we go for it. We r changing the extract structure right, that means there are some newly added fields in that which r not before. So to get the required data (i.e.; the data which is required is taken and to avoid redundancy) we delete n then fill the setup tables.
    To refresh the statistical data. The extraction set up reads the dataset that you want to process such as, customers orders with the tables like VBAK, VBAP) & fills the relevant communication structure with the data. The data is stored in cluster tables from where it is read when the initialization is run. It is important that during initialization phase, no one generates or modifies application data, at least until the tables can be set up.

  • Error while deleting a customer table

    When I try to delete a customer table which is saved as a local object I get an error stating that the table is still used in ABAP Dictionary. It seems that the customer table is still used in a customer program, but the program is already deleted! I deleted the program earlier and thus no longer exist in our system. I cannot find any trace of the program, but am unable to delete the customer table now. Any suggestions?

    Program name would have been of the table maintenance generator and you deleted it manually.
    It should have been deleted from TMG .
    Your problem will be resolved if you will create Table maintenance of the database table and then delete it again.

  • Using Insert and Delete icons in table control wizard.

    Can anyone tell me how to perform a new row insertion or deletion in a table created using the table control wizard.
    I see there is a form fcode_insert_row and fcode_delete_row, but dont know how to call them and what parameters to pass and all.
    Since iam new to SAP-ABAP, some code samples will be a great help.
    Thanks to all in advance.

    Hi Lavanya ,
    You have to add the icons personally in the table control.. . Put fcode for addition button as INSE and delete as DELE ..coding will be already thr in the wizard no need to anything just add icons in the table control by selecting from f4 help on icons option of screen.
    Thanks,
    Vishnu .

  • How to delete the source table rows once loaded in Destination Table in SSIS?

    Data Base=kssdata
    Tables= Userdetails having 1000 rows
    Using SSIS: 
    Taking A  
    OLE DB Source----------------->OLE DB Destination
    Am Taking 200 rows in Source table and loaded into Destination table once
    Constraint: here once 200 rows are exported in destination table , that 200 rows are deleted in source table
    repeat the task as source table all the records are loaded into Destination table 
    After that am taking another 200 rows in source table and loaded into Destination table

    Provided you've a sequential primary key  or audit timestamp (datetime/date) column in the table you can do an approach like this
    1. Add a execute sql task connectng to source db with below statement
    SELECT COUNT(*) FROM table
    Store the result in a variable
    2. Have another variable and set it to below expression
    (@[User::CountVariable]/200) + (@[User::CountVariable]%200 >0? 1:0)
    by setting EvaluatesExpression as true. Here CountVariable is variable created in previous step
    3. Have a for loop container with below settings
    InitExpression
    @NewVariable = @CounterVariable
    EvalExpression
    @NewVariable > 0
    AssignExpression
    @NewVariable = @NewVariable - 1
    3. Add a data flow task with OLEDB source and OLEDB Destination
    4. Use source query as
    SELECT TOP 200 columns...
    FROM Table
    ORDER BY [PK | AuditColumn]
    Use PK or audit column depending which one is sequential
    5. After data flow task have a execute sql task with statement as below
    DELETE t
    FROM (SELECT ROW_NUMBER() OVER (ORDER BY PK) AS Rn
    FROM Table)t
    WHERE Rn <= 200
    This will make sure the 200 records gets deleted each time
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

Maybe you are looking for

  • How can I hide the Event Index by default in Connect 9 recordings?

    We do not use the Event index in our recordings, and the fact that it is open when the recording launches for anyone who views it, is problematic.  We embed the recordings on our website, and it is messing up the embeds (the Event Index is taking up

  • Error while integrating Windows System - Share into KM

    Hi Experts, I am new to KM and there is a requirement of Integrating Windows System into KM. Portal System : a.xyz.com Remote System: b.xyz.com Share - b.xyz.com\d_share$ Both systems reside in the same domain and share is created on the remote syste

  • Problem in sender JDBC adapter

    hello, I am facing one typical problem in sender JDBC adapter. Here is the issue, JDBC API method getString threw an exception: java.sql.SQLException: Cursor state not valid. Can anyone please help me out in solving this problem? Actually after a ret

  • Form problem with less than (le)

    I have a form, when users push the next button there will be some input field checking before the user is realy going to the next page. Now I want to check if the zip code (Netherlands) is not less than 6 postions. In the begining I used this code: i

  • Out of Memory (OOM) - Kernel Freezing

    Linux BLOZUP 3.17.6-1-ARCH #1 SMP PREEMPT Sun Dec 7 23:43:32 UTC 2014 x86_64 GNU/Linux 240GB SSD, encypted with dm-crypt 4GB RAM No swap XFCE4 Desktop Every once and a while it appears that my kernel freezes. Mouse movement grinds to a halt, but occa