Delete rows from JTable
Hello
I use a JTable with a custom table model that extends javax.swing.table.DefaultTableModel.
I haven't overwrote the method
public void removeRow(int row)Now when i use this method the rows always get removed from the end. It doesn't matter which value the parameter row has.
Even when i call
myTableModel.removeRow( 0 );it removes the rows at the end of the table.
It would be nice if someone could help me with this.
Regards, Michelle
It's not so easy to do this because it's a big project, but here is the code of the table model.
import javax.swing.table.*;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import java.util.*;
public class AssignmentsTableModel2 extends DefaultTableModel implements TableModelListener
static final long serialVersionUID = 41L;
public AssignmentsTableModel2(String[][] arg1, String[] arg2)
super(arg1, arg2);
public Vector getColumnIdentifiers()
return columnIdentifiers;
@Override
public int getColumnCount()
return this.columnIdentifiers.size();
@Override
public int getRowCount()
return this.dataVector.size();
@Override
public String getColumnName(int col)
return (String)this.columnIdentifiers.elementAt( col );
@Override
public Object getValueAt(int rowIndex, int columnIndex)
return ((Vector)this.dataVector.elementAt( rowIndex )).elementAt( columnIndex );
@Override
public void setValueAt( Object val, int rowIndex, int columnIndex )
((Vector)this.dataVector.elementAt( rowIndex )).set( columnIndex, val);
fireTableCellUpdated( rowIndex, columnIndex );
@Override
public void tableChanged(TableModelEvent e)
@Override
public void setColumnIdentifiers(Vector columnIdentifiers)
super.setColumnIdentifiers(columnIdentifiers);
@Override
public void removeRow(int row)
this.dataVector.remove(row);
System.out.println(row + " to remove");
this.fireTableStructureChanged();
//super.removeRow(row);
}I need the model to change the background color of the cells at runtime and I now overwrote the removeRow() method, but it's still the same problem.
Also I have a custom JTable class that colours the TableHeader of the selected column.
class PaintedTable extends JTable {
private static final long serialVersionUID = 1L;
PaintedTable(AssignmentsTableModel2 atm)
super(atm);
setOpaque(false);
((JComponent) getDefaultRenderer(Object.class)).setOpaque(false);
@Override
public void paintComponent(Graphics g)
//System.out.println("paint table");
Color background = new Color(168, 210, 241);
Color controlColor = new Color(230, 240, 230);
int width = getWidth();
int height = getHeight();
Graphics2D g2 = (Graphics2D) g;
Paint oldPaint = g2.getPaint();
g2.setPaint(new GradientPaint(0, 0, background, width, 0, controlColor));
g2.fillRect(0, 0, width, height);
g2.setPaint(oldPaint);
for (int row : getSelectedRows())
Rectangle start = getCellRect(row, 0, true);
Rectangle end = getCellRect(row, getColumnCount() - 1, true);
g2.setPaint(new GradientPaint(start.x, 0, Color.orange, (int) ((end.x + end.width - start.x) * 1.25), 0, controlColor));
g2.fillRect(start.x, start.y, end.x + end.width - start.x, start.height);
//System.out.println("rect: (" + start.x + ", " + start.y + ") + (" + (end.x + end.width - start.x) + ", " + start.height +")");
super.paintComponent(g);
public boolean isCellEditable(int rowIndex, int colIndex)
return false;
AssignmentsTableModel2 atm = new AssignmentsTableModel2(this.columnValues, this.columnHeaders);
PaintedTable table = new PaintedTable( this.atm );
Similar Messages
-
Hello,
I've got a JTable which is based on a 2-dimensional array, which contains my data. Now I want to delete several rows from the JTable. There's the possibility to modify my data-array by creating a new array which doesn't contain anymore the datasets I want to delete. Afterwards I can redraw the table and my rows are deleted. But I think that's a very complicated way to delete rows from a JTable. Can anybody tell me whether ther's an easier way to do so ? I'd really be pleased...
Thanx,
FindusWhen you create a TableModel using a two-dimensional array or a Vector of Vectors, a DefaultTableModel is created and it stores the data in its own Vector of Vectors. The DefaultTableModel supports methods for adding/removing rows of data. To remove the first row in the table you would do something like:
DefaultTableModel model = (DefaultTableModel)table.getModel();
model.removeRow( 0 );
Note: once you create the TableModel you should set your array to null as it is not used anymore. -
Problem in adding/deleting rows in JTable
I am trying to add /remove rows from JTable whose first column is JButton and others are JComboBox's.If no rows are selected,new row is added at the end.If user selects some row & then presses insert button,new row is added below it.Rows can only be deleted if user has made some selection.Kindly help me,where i am making mistake.If any function is to be used.My code is as follows....
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
public class JButtonTableExample extends JFrame implements ActionListener{
JComboBox mComboLHSType = new JComboBox();
JComboBox mComboRHSType = new JComboBox();
JLabel mLabelLHSType = new JLabel("LHS Type");
JLabel mLabelRHSType = new JLabel("RHS Type");
JButton mButtonDelete = new JButton("Delete");
JButton mButtonInsert = new JButton("Insert");
JPanel mPanelButton = new JPanel();
JPanel mPanelScroll = new JPanel();
JPanel mPanelCombo = new JPanel();
DefaultTableModel dm ;
JTable table;
int currentRow = -1;
static int mSelectedRow = -1;
public JButtonTableExample()
super( "JButtonTable Example" );
makeForm();
setSize( 410, 222 );
setVisible(true);
private void makeForm()
this.getContentPane().setLayout(null);
mPanelCombo.setLayout(null);
mPanelCombo.setBorder(new LineBorder(Color.red));
mPanelCombo.setBounds(new Rectangle(1,1,400,30));
mLabelLHSType.setBounds(new Rectangle(26,5,71,22));
mComboLHSType.setBounds(new Rectangle(83,5,100,22));
mLabelRHSType.setBounds(new Rectangle(232,5,71,22));
mComboRHSType.setBounds(new Rectangle(292,5,100,22));
mPanelCombo.add(mLabelLHSType,null);
mPanelCombo.add(mComboLHSType,null);
mPanelCombo.add(mLabelRHSType,null);
mPanelCombo.add(mComboRHSType,null);
mPanelScroll.setLayout(null);
mPanelScroll.setBorder(new LineBorder(Color.blue));
mPanelScroll.setBounds(new Rectangle(1,28,400,135));
mPanelButton.setLayout(null);
mPanelButton.setBorder(new LineBorder(Color.green));
mPanelButton.setBounds(new Rectangle(1,165,400,30));
mButtonInsert.setBounds(new Rectangle(120,5,71,22));
mButtonDelete.setBounds(new Rectangle(202,5,71,22));
mButtonDelete.addActionListener(this);
mButtonInsert.addActionListener(this);
mPanelButton.add(mButtonDelete,null);
mPanelButton.add(mButtonInsert,null);
dm = new DefaultTableModel();
//dm.setDataVector(null,
//new Object[]{"Button","Join","LHS","Operator","RHS"});
dm.setDataVector(new Object[][]{{"","","","",""}},
new Object[]{"","Join","LHS","Operator","RHS"});
table = new JTable(dm);
table.getTableHeader().setReorderingAllowed(false);
table.setRowHeight(25);
int columnWidth[] = {20,45,95,95,95};
TableColumnModel modelCol = table.getColumnModel();
for (int i=0;i<5;i++)
modelCol.getColumn(i).setPreferredWidth(columnWidth);
//modelCol.getColumn(0).setCellRenderer(new ButtonRenderer());
//modelCol.getColumn(0).setCellEditor(new ButtonEditor(new JCheckBox()));
modelCol.getColumn(0).setCellRenderer(new ButtonCR());
modelCol.getColumn(0).setCellEditor(new ButtonCE(new JCheckBox()));
modelCol.getColumn(0).setResizable(false);
setUpJoinColumn(modelCol.getColumn(1));
setUpLHSColumn(modelCol.getColumn(2));
setUpOperColumn(modelCol.getColumn(3));
setUpRHSColumn(modelCol.getColumn(4));
JScrollPane scroll = new JScrollPane(table);
scroll.setBounds(new Rectangle(1,1,400,133));
mPanelScroll.add(scroll,null);
this.getContentPane().add(mPanelCombo,null);
this.getContentPane().add(mPanelScroll,null);
this.getContentPane().add(mPanelButton,null);
}//end of makeForm()
public void actionPerformed(ActionEvent ae)
if (ae.getSource() == mButtonInsert)
//int currentRow = table.getSelectedRow();
currentRow = ButtonCE.selectedRow;
System.out.println("Before Insert CURRENT ROW"+currentRow);
if(currentRow == -1)
int rowCount = dm.getRowCount();
//mSelectedRow = rowCount-1;
//table.clearSelection();
dm.insertRow(rowCount,new Object[]{"","","","",""});
currentRow = -1;
ButtonCE.selectedRow = -1;
else
table.clearSelection();
dm.insertRow(currentRow+1,new Object[]{"","","","",""});
currentRow = -1;
ButtonCE.selectedRow = -1;
//System.out.println("After INSERT CURRENT ROW"+currentRow);
if(ae.getSource() == mButtonDelete)
//int currentRow = table.getSelectedRow();
currentRow = ButtonCE.selectedRow;
System.out.println("Before DELETE CURRENT ROW"+currentRow);
if(currentRow != -1)
dm.removeRow(currentRow);
table.clearSelection();
currentRow = -1;
ButtonCE.selectedRow = -1;
//System.out.println("Selected Row"+mSelectedRow);
else
JOptionPane.showMessageDialog(null, "Select row first", "alert", JOptionPane.ERROR_MESSAGE);
//System.out.println("DELETE CURRENT ROW"+currentRow);
public void setUpJoinColumn(TableColumn joinColumn)
//Set up the editor for the sport cells.
JComboBox comboBox = new JComboBox();
comboBox.addItem("AND");
comboBox.addItem("OR");
comboBox.addItem("NOT");
joinColumn.setCellEditor(new DefaultCellEditor(comboBox));
//Set up tool tips for the sport cells.
DefaultTableCellRenderer renderer =
new DefaultTableCellRenderer();
renderer.setToolTipText("Click for combo box");
joinColumn.setCellRenderer(renderer);
//Set up tool tip for the sport column header.
TableCellRenderer headerRenderer = joinColumn.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer) {
((DefaultTableCellRenderer)headerRenderer).setToolTipText(
"Click the sport to see a list of choices");
public void setUpLHSColumn(TableColumn LHSColumn)
//Set up the editor for the sport cells.
JComboBox comboBox = new JComboBox();
comboBox.addItem("Participant1");
comboBox.addItem("Participant2");
comboBox.addItem("Variable1");
LHSColumn.setCellEditor(new DefaultCellEditor(comboBox));
//Set up tool tips for the sport cells.
DefaultTableCellRenderer renderer =
new DefaultTableCellRenderer();
renderer.setToolTipText("Click for combo box");
LHSColumn.setCellRenderer(renderer);
//Set up tool tip for the sport column header.
TableCellRenderer headerRenderer = LHSColumn.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer) {
((DefaultTableCellRenderer)headerRenderer).setToolTipText(
"Click the sport to see a list of choices");
public void setUpOperColumn(TableColumn operColumn)
//Set up the editor for the sport cells.
JComboBox comboBox = new JComboBox();
comboBox.addItem("=");
comboBox.addItem("!=");
comboBox.addItem("Contains");
operColumn.setCellEditor(new DefaultCellEditor(comboBox));
//Set up tool tips for the sport cells.
DefaultTableCellRenderer renderer =
new DefaultTableCellRenderer();
renderer.setToolTipText("Click for combo box");
operColumn.setCellRenderer(renderer);
//Set up tool tip for the sport column header.
TableCellRenderer headerRenderer = operColumn.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer) {
((DefaultTableCellRenderer)headerRenderer).setToolTipText(
"Click the sport to see a list of choices");
public void setUpRHSColumn(TableColumn rhsColumn)
//Set up the editor for the sport cells.
JComboBox comboBox = new JComboBox();
comboBox.addItem("Variable1");
comboBox.addItem("Constant1");
comboBox.addItem("Constant2");
rhsColumn.setCellEditor(new DefaultCellEditor(comboBox));
//Set up tool tips for the sport cells.
DefaultTableCellRenderer renderer =
new DefaultTableCellRenderer();
renderer.setToolTipText("Click for combo box");
rhsColumn.setCellRenderer(renderer);
//Set up tool tip for the sport column header.
TableCellRenderer headerRenderer = rhsColumn.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer) {
((DefaultTableCellRenderer)headerRenderer).setToolTipText(
"Click the sport to see a list of choices");
public static void main(String[] args) {
JButtonTableExample frame = new JButtonTableExample();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
//Button as a renderer for the table cells
class ButtonCR implements TableCellRenderer
JButton btnSelect;
public ButtonCR()
btnSelect = new JButton();
btnSelect.setMargin(new Insets(0,0,0,0));
public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column)
if (column != 0) return null; //meany !!!
//System.out.println("Inside renderer########################Selected row");
//btnSelect.setText(value.toString());
//btnSelect.setIcon(new ImageIcon("capsigma.gif"));
return btnSelect;
}//end fo ButtonCR
//Default Editor for table
class ButtonCE extends DefaultCellEditor implements ActionListener
JButton btnSelect;
JTable table;
//Object val;
static int selectedRow = -1;
public ButtonCE(JCheckBox whoCares)
super(whoCares);
//this.row = row;
btnSelect = new JButton();
btnSelect.setMargin(new Insets(0,0,0,0));
btnSelect.addActionListener(this);
setClickCountToStart(1);
public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int column)
if (column != 0) return null; //meany !!!
this.selectedRow = row;
this.table = table;
table.clearSelection();
System.out.println("Inside getTableCellEditorComponent");
return btnSelect;
//public Object getCellEditorValue()
//return val;
public void actionPerformed(ActionEvent e)
// Your Code Here...
System.out.println("Inside actionPerformed");
System.out.println("Action performed Row selected "+selectedRow);
btnSelect.setIcon(new ImageIcon("capsigma.gif"));
}//end of ButtonCEHi,
All the thing you have to do is to return a boolean for the column. JTable will use a checkbox (as default) to show boolean values. -
Delete rows from table...Bizarre problem.
Folks
i HAVE this bizarre problem.
I hava a Java class which displays data read into a table with a delete
option by the side of each row.
Now lets assume you have 3 rows in the Table.
abc deleteButton
efg deleteButton
xyz deleteButton
When I click the first delete,that row gets deleted from the table.(perfect...)
Now I have 2 rows.
When I click on the first row,I get the error
'You clicked -1'
java.lang.ArrayIndexOutofBoundsException: -1 < 0.
Can anyone tell me why this is happening even though there are rows in the table.???
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("You clicked row : " + table.getSelectedRow());
javax.swing.table.TableModel model = table.getModel();
Object o = model.getValueAt(table.getSelectedRow(),0);
//System.out.print(model.getValueAt(table.getSelectedRow(), 0));
//System.out.println();
MyDeleteFunction(o.toString());
// Delete row from window.
((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
table.revalidate();
table.repaint();Hi ritu,
This class is called
new DisplayCall_IDTodisconnect(hashTable);
its a long file.
its attached below.
The rows are displayed by reading a hashtable into a vector
and the vector is iterated and appended..
public class DisplayCall_IDToDisconnect {
public static JTable createTable(Vector data, String buttonLabel, ActionListener action){
return createTable(data.iterator(), buttonLabel, action);
public static JTable createTable(
Iterator dataIterator,
String buttonLabel,
ActionListener action) {
DefaultTableModel model = new DefaultTableModel() {
public boolean isCellEditable(int row, int col) {
return col == 1;
model.setColumnCount(2);
while (dataIterator.hasNext()) {
Object[] row = { dataIterator.next().toString(), null };
model.addRow(row);
DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
columnModel.addColumn(new TableColumn(0, 100));
columnModel.addColumn(new TableColumn(1, 80,
new TableButtonCellRenderer(buttonLabel),
new TableButtonCellEditor(buttonLabel, action)
JTable table = new JTable(model, columnModel) {
public void valueChanged(ListSelectionEvent e) {
super.valueChanged(e);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
return table;
private static class TableButtonCellRenderer implements TableCellRenderer {
final JButton button;
TableButtonCellRenderer(String buttonLabel) {
button = new JButton(buttonLabel);
public Component getTableCellRendererComponent(
JTable table,
Object value,
boolean isSelected,
boolean hasFocus, int row, int column) {
return button;
private static class TableButtonCellEditor
extends AbstractCellEditor
implements TableCellEditor, ActionListener {
final JButton button;
final ActionListener callback;
TableButtonCellEditor(String buttonLabel, ActionListener callback) {
button = new JButton(buttonLabel);
this.callback = callback;
button.addActionListener(this);
public Component getTableCellEditorComponent(
JTable table,
Object value,
boolean isSelected,
int row, int column) {
return button;
public Object getCellEditorValue() {
return null;
public void actionPerformed(ActionEvent e) {
button.getParent().requestFocus();
callback.actionPerformed(e);
static JTable table;
Vector items;
final ClientManager clientMgr;
// Constructor.
public DisplayCall_IDToDisconnect(Hashtable callLegTable,ClientManager clientMgr){
Vector vCSeqnos = displayCSeqNos(callLegTable);
this.clientMgr = clientMgr;
JFrame frame = new JFrame("Disconnect Options");
/*Vector*/ items = new Vector();
Enumeration vEnum = vCSeqnos.elements();
while(vEnum.hasMoreElements()){
items.add(vEnum.nextElement());
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("You clicked row ,col: " + table.getSelectedRow()+
// table.getSelectedColumn());
javax.swing.table.TableModel model = table.getModel();
Object o = model.getValueAt(table.getSelectedRow(),0);
System.out.print(model.getValueAt(table.getSelectedRow(), 0));
System.out.println();
closeConnection(o.toString());
// Delete row from window too.
((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
table.revalidate();
table = DisplayCSeqNos.createTable(items, "Disconnect", al);
frame.getContentPane().add(new JScrollPane(table));
frame.pack();
frame.show();
} // End Constructor.
public void closeConnection(String s){
/*1. Disconnect the current session*/
this.clientMgr.disconnectCall(s);
/*2. refresh the Disconnect window*/
this.refreshWindow();
public Vector displayCSeqNos(Hashtable callLegTable){
Enumeration eNum;
String str;
Vector v = new Vector();
eNum=callLegTable.keys();
while(eNum.hasMoreElements()){
str = (String) eNum.nextElement();
//System.out.println("Key : " + str + " Value : " + callLegTable.get(str));
v.addElement(str);
return v;
} // End of displayCSeqNos. -
Delete Rows from T1 which are Not in T2
Hi
I've 2 Tables like below
T1
N1
N2
2
11
2
22
3
33
8
44
8
88
T2
N1
N2
2
22
8
88
If I Run Delete query, I must delete Rows from T1 which are Not in T2
For example, I must delete Rows 1,3,4 from T1
So how to write that delete query? Please adviceDelete from T1
Where not Exists (select * from T2 Where t1.N1=t2.N1 and t1.N2=t2.N2)
--or
Delete t
From t1 t
left JOIN t2 m
ON m.N1=t.N1 and m.N2=t.N2
WHERE m.N1 is null and m.N2 is null
--Or
;With mycte as
select N1,N2 from T1
Except
select N1,N2 from T2
Delete t
From t1 t
INNER JOIN mycte m
ON m.N1=t.N1 and m.N2=t.N2 -
Cannot DELETE rows from LOV on running...is it a bug ??
One of the features I appreciated in the new version of JHeadstart is that we can now insert, modify and delete rows on LOV (even in the database).
We have just to check on Lookup properties :
Multi-row insert allowed
Multi-row update allowed
Multi-row delete allowed
I cheked all of them and on runnig I could insert and update records in LOV.
When I tried to delete records from LOV the system display information message "nothing to save" and in fact no records were deleted.
Normally since I checked the delete property it should be possible to delete rows from LOV
thanks for any HelpMonta,
I could reproduce this, it is a bug. Added to the fix list for the next release.
Thanks for reporting,
Steven Davelaar,
JHeadstart Team. -
Unable to delete rows from Target.
Hello everyone,
I am unable to delete rows from target data store. Here is what I have done.
Source Oracle 10g - staging 11g - Target Oracle 11g
I have implemented consistent set CDC on data model in staging and added 2 tables to CDC and turned on the journals . Both tables A and B are joined together via Column E (primary key of table A). Table A is the master table(has foreign key). Table B is child table. Target column consists of all the columns of both table A and B.
Following is what I am able to do and not to do
ABLE TO DO. If data is inserted into both or any of journalized tables I can successfully load the same in target by performing following steps. 1. Extend the consistency window at model level. Lock subscriber. Run the interface with any source table marked as Journalized data only. Unlock subscriber and purge journal.
ABLE TO DO. If data is updated in any of the journalized table, along with the steps mentioned above I can execute two interfaces. In one Interface table A marked as journalized data only Joined with table B and in second interface table B marked as Journalized data only joined to table a.
NOT ABLE TO DO If data is deleted from one or both tables it shows up as journalized data in JV$D<tablename> marked as D with date and subscriber name but when i run the interface by extending the window , locking subscriber executing both interfaces, unlock subscriber purge journals. no change takes place is Target. After unlocking subscriber step, journalized data gets removed from JV$D view. Please let me know what I am doing wrong here. How can rows delted from source can also be deleted from TARGET?
NOTE : In the flow table SYNC_JRNL_DELETES is YES
In moel under jounalized table tab Table have following order Table A folloed by Table B
Thanks in advance
GreenwichSorry I still do not get it. when you say "Its a legacy app", are you talking about the VB.NET app ?
If so then I repeat my self :-) Why not to connecting to the SQL server directly?
* even if you need information from several databases (for example ACCESS + SQL Server), in most cases, it is much better to connect directly and get each information to the app. Then in your app you can combine the information and analyse it
[Personal Site] [Blog] [Facebook]
Access app is the legacy app. -
COuld anyone tell me how to delete rows from a table which has millions of rows.
TIA,
Oracle userif you are deleting all the rows, use "truncate table" in sql*plus.
or if you are deleting all but a handful of rows, then copy the rows you still want to a spare table, drop the original table, and rename the spare table back to the original table's name.
hope this helps -
How to remove a row from JTable
Hi!
I'm used to remove rows from JTables getting the model and doing a removeRow(num) like this:
((DefaultTableModel)jTable1.getModel()).removeRow(0);
But with ADF and JDeveloper the model says it's a JUTableBinding.JUTableModel but its not accessible.
How to remove a row in Jdeveloper 10.1.3.4.0?Or maybe is just better to refresh data in the jTable but I do not know either like doing it.
-
Oracle deleting rows from tables starting with the name PQ
hai friends
we are given access rights to delete only tables starting with PQ. HAVING PQ_NUM as primary key for all the PQ tables.
totally we have 6 tables. PQ_01,PQ_02, PQ_03,PQ_04,PQ_05,PQ_06.
ALL This tables will have one primary key. for example pq_01 willl have pq01_num as primarykey and pq_02 table will have pq02_num as primary
key.
pq01_num value will exist in all the primary key of pq tables.
i want query to delete rows from the pq tables based on the input value i give.
for example if i give primarykey value 122 then that value in pq tables should be deleted.
One more problem is there. pq_06 table does not have pq02_num column. here the column differs. it is pq06_num_req.
so give your idea of deleting the rows from pq tables
waiting
SI dont have access to databse,this is untested
declare
v_cmd varchar2(2000);
columnname varchar2(30);
input_value number:=??;
tabowner varchar2(30):=???
begin
--step 1 identify table
FOR sub IN (SELECT table_name table_to_delete
FROM all_tables
WHERE table_name LIKE 'PQ%'
and owner=tabowner
) LOOP
----step 2 identify column
v_cmd :='select t.column_name from all_constraints S,All_Ind_Columns T where
S.OWNER=T.TABLE_OWNER
AND S.TABLE_NAME=T.TABLE_NAME
AND S.INDEX_NAME=T.INDEX_NAME
and s.owner=tabowner
AND S.TABLE_NAME='||table_to_delete||'
and s.constraint_type='''P'';
execute immediate v_cmd into columnname;
--step 3 delete records
v_cmd := 'delete from '||tabowner||'.' ||
sub.table_to_delete || '
where '||columnname||'='||input_value;
execute immediate v_cmd;
commit;
END LOOP;
end;Edited by: user5495111 on Aug 11, 2009 6:35 AM -
Hi,
Anyone knows how dynamicly delete rows from Tabular Form (on button click, button is as item)?
Thanks.I am in a great fix. We had a test instance.. and we had a version apex 3.2.. But when the same application has been uploaded to prod.. we used apex 4.0.Why on Earth would you do this? The whole point of the testing is to verify that the application will work in the production environment: the first requirement for this is that the test and production environments are equivalent.
has any body is facing the same issue as mine..Yes, as is easily discovered by searching the forum...see Delete button doesn't work in tabular form after upgrade from APEX3.2 to 4. -
Add/Delete rows from ALV-grid
Hi to all,
i have 2 questions concerning alv-grids:
i have an alvgrid displaying a table and what i need is some functionality to add or delete rows from the alvgrid - how can i do that ?
within one row i have one field containing the status and i want to be able to select the status from a combo/dropdown-field and set it for this particular row.
thanks in advance!Hi,
Report BCALV_EDIT_04 shows how to append and delete rows.
Report BCALV_EDIT_06 shows drop down list for cells in a column.
These report should be available in any R/3 system including all ABAP Preview versions.
Hope this can help.
Regards, Johan -
Deleting rows from very large table
Hello,
I need to delete rows from a large table, but not all of them, so I can't use truncate. The delete condition is based on one column, something like this:
delete from very_large_table where col1=100;
There's an index (valid, B-tree) on col1, but it still goes very slow. Is there any instruction which can help delete rows faster?
Txh in adv.
A.Your manager doesn't agree to your running an EXPLAIN PLAN? What is his objection? Sounds like the prototypical 'pointy-hair boss'.
Take a look at these:
-- do_explain.sql
spool explain.txt
-- do EXPLAIN PLAN on target queries with current index definitions
truncate table plan_table
set echo on
explain plan for
<insert query here>
set echo off
@get_explain.sql
-- get_explain.sql
set linesize 120
set pagesize 70
column operation format a25
column query_plan format a35
column options format a15
column object_name format a20
column order format a12
column opt format a6
select lpad(' ',level) || operation "OPERATION",
options "OPTIONS",
decode(to_char(id),'0','COST = ' || NVL(to_char(position),'n/a'),object_name) "OBJECT NAME",
cardinality "rows",
substr(optimizer,1,6) "OPT"
from plan_table
start with id = 0
connect by prior id = parent_id
There are probably newer, better ways, but this should work with all living versions of Oracle and is something I've had in my back pocket for several years now. It's not actually executing the query or dml in question, just running an explain plan on it. -
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. -
I am trying to delete a row from a JTable whenever the button on the last column is pressed. I know to do this, I can use the removeRow(int) method of the tableModel. But the odd thing is when I try to get a handle to the TableModel from the JTable to use that function, i.e. table.getModel().removeRow(int) it doesn't work. But if I explicitly pass in the tableModel into my class it does work. Here's the code below:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.UIManager;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableCellEditor;
import javax.swing.AbstractCellEditor;
import javax.swing.table.DefaultTableModel;
public class tester4 extends JFrame
protected final int BUTTON_COL = 2;
private TableCellRenderer defaultRenderer;
private TableCellEditor defaultEditor;
private JTable workingTable;
private String[] transactionCols = {"Qty", "Product", "Cancel"};
private Object[][] data = {{5, "prod1", "Cancel"},
{6, "prod2", "Cancel"},
{7, "prod3", "Cancel"}};
public tester4()
workingTable = new JTable(tableModel);
workingTable.setName("Working Table");
defaultRenderer = workingTable.getDefaultRenderer(JButton.class);
defaultEditor = workingTable.getDefaultEditor(Object.class);
StatusTableRenderer testRenderer = new StatusTableRenderer(defaultRenderer, defaultEditor, workingTable, tableModel);
workingTable.setDefaultRenderer(Object.class, testRenderer);
workingTable.setDefaultEditor(Object.class, testRenderer);
JScrollPane scrollPane = new JScrollPane( workingTable );
getContentPane().add( scrollPane );
private DefaultTableModel tableModel = new DefaultTableModel(data, transactionCols){
// Only allow button column to be editable, if there is an actual
// button in that row
public boolean isCellEditable(int row, int col){
return (col == BUTTON_COL && data[row][col] != "") ? true : false;
// Overriden getColumnClass method that will return the object
// class type of the first instance of the data type otherwise
// returns the Object.class
public Class getColumnClass(int column){
for (int row = 0; row < getRowCount(); row++){
Object o = getValueAt(row, column);
if (o != null){ return o.getClass(); }
return Object.class;
public static void main(String[] args)
tester4 frame = new tester4();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
public class StatusTableRenderer extends AbstractCellEditor
implements TableCellRenderer,
TableCellEditor,
ActionListener{
private TableCellRenderer defaultRenderer;
private TableCellEditor defaultEditor;
private JButton cancelButton;
private JButton editButton;
private String text;
private int buttonColumn;
private int selectedRow;
private JTable table;
private DefaultTableModel tableModel;
public StatusTableRenderer(TableCellRenderer renderer,
TableCellEditor editor,
JTable table,
DefaultTableModel tableModel){
defaultRenderer = renderer;
defaultEditor = editor;
this.table = table;
this.tableModel = tableModel;
buttonColumn = table.getColumnCount() - 1;
cancelButton = new JButton();
editButton = new JButton();
editButton.setFocusPainted(true);
editButton.addActionListener(this);
public StatusTableRenderer(TableCellRenderer renderer,
TableCellEditor editor,
JTable table,
DefaultTableModel tableModel,
int _buttonColumn){
this(renderer, editor, table, tableModel);
buttonColumn = _buttonColumn;
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (column == buttonColumn){
if (hasFocus){
cancelButton.setForeground(table.getForeground());
cancelButton.setBackground(UIManager.getColor("Button.background"));
else if (isSelected){
cancelButton.setForeground(table.getSelectionForeground());
cancelButton.setBackground(table.getSelectionBackground());
else{
cancelButton.setForeground(table.getForeground());
cancelButton.setBackground(UIManager.getColor("Button.background"));
cancelButton.setText( (value == null) ? "" : value.toString() );
return cancelButton;
return defaultRenderer.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column);
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column){
if (column == buttonColumn){
text = ((value == null) ? "": value.toString());
editButton.setText(text);
selectedRow = row;
return editButton;
return defaultEditor.getTableCellEditorComponent(
table, value, isSelected, row, column);
public Object getCellEditorValue()
return text;
public void actionPerformed(ActionEvent e)
fireEditingStopped();
// This works
tableModel.removeRow(selectedRow);
// This does not work
// table.getModel().removeRow(selectedRow);
}Take a look at the actionPerfformed method. One way of doing it works, one doesn't. Just trying to understand why me getting a handle to the tableModel through the table doesn't work.
Message was edited by:
deadseasquirrelsIt gives me a run-time error Well then your question should be "why do I get this run-time error" and then you would quote the error. Be more descriptive. "It doesn't work" is not descriptive.
table.getModel().removeRow(selectedRow);I don't use JDK1.5 either. But if you are saying that the above line compiles cleanly with JDK1.5 (because of the auto-boxing feature, or whatever its called), then I see no reason why the code wouldn't work since it recognizes the class as a DefaultTableModel.
Presumably you commented out the other line so you don't try to delete the row twice. Otherwise you might be getting a indexing error.
Maybe you are looking for
-
Acrobat 8 Pro, OS X 10.5.7 Acrobat does not appear to able to undo an action when editing forms. A co-worker is working on a multipage form that was created in ID and exported to PDF. In Acrobat, she is creating form fields. Inadvertently, she has se
-
Is there any way to bypass the xlate table. We have no requirement for NAT on our FWSM however every time a change is made we must clear the xlate table. I have tried using NAT exemption however entries still appear in the xlate table. Any ideas?
-
Print Boilerplate once per page
How can I print boilerplate once per page in between parent and child records? I tried using a summary column with Reset-At:Page, but I can't reference a Page-level column within a Format trigger. Any other ideas? (thanks in advance) pat
-
Hey everyone, I am using the cfscript I got for a calendar from this website: http://www.drisgill.com/files/cal.txt Its fairly straight forward and displayed a generic plain calendar for the month. I am trying to make it so the calendar fills dynami
-
Hi, Recently while using Spotify my music sometimes just stops playing. I go to open Spotify and only the very top bar of the program appears (Where the minimize, close, and mazimize buttons are, nothing else is shown). So I close spotify and try to