why occurs error when cancelRowInsert() -- a CachedRowSet and JTable problem
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   X_F
Posted On:   Tuesday, May 21, 2002 07:36 PM

crs.beforeFirst(); //crs is object of CachedRowSet while(crs.next()){ if(crs.rowInserted()){ crs.cancelRowInsert(); } } i want to cancel the inserted rows , but the result is not expected. I use 'crs' for JTable's model data: TableModel myTableModel = new AbstractTableModel() { public int getColumnCount() {...} public int getRowCount() { try{ return crs.size(); }catch(Exception e){ return 0; } } public Object getValueAt(int row, int col) { try{ crs.absolute(row+1); return crs.getString(col+1); }catch(Exception e){ return ""; } }    More>>
			

crs.beforeFirst(); //crs is object of CachedRowSet

while(crs.next()){
if(crs.rowInserted()){
crs.cancelRowInsert();
}
}

i want to cancel the inserted rows , but the result is not expected.


I use 'crs' for JTable's model data:

TableModel myTableModel = new AbstractTableModel() {
public int getColumnCount() {...}
public int getRowCount() {
try{
return crs.size();
}catch(Exception e){
return 0;
}
}
public Object getValueAt(int row, int col) {
try{
crs.absolute(row+1);
return crs.getString(col+1);
}catch(Exception e){
return "";
}
}
public String getColumnName(int column) {...;}
public Class getColumnClass(int col) {return String.class;}
public boolean isCellEditable(int row, int col) {return true;}
public void setValueAt(Object aValue, int row, int col) {
try{
crs.absolute(row+1);
crs.updateString(col+1, aValue.toString());
}catch(Exception e){ e.printStackTrace();
}
}
};

myTable.setModel(myTableModel);

when somebody insert a new record into jtable, he would be permitted to cancel insertion. but when i test -- insert 10 records and then delete these, i found that the first inserted record couldn't be cancelled, and ......

private void delete(){
try{
crs.absolute(myTable.getSelectedRow()+1);
if(crs.rowInserted()){

// this should cancel current record but actually cancel the next record!!!
crs.cancelRowInsert();

}
myTable.revalidate();
}catch(Exception e){

//when cancel the first inserted record after others new records cancelled, here will be executed!
e.printStackTrace();
}
}


error occurs :
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 3
at java.util.Vector.remove(Vector.java:782)
at sun.jdbc.rowset.CachedRowSet.cancelRowInsert(CachedRowSet.java:921)
.....
...



thanks your time!

   <<Less
About | Sitemap | Contact