public int deleteRow ( ) { // build the delete string String deleteString = "DELETE FROM " + tableName + this . generatePKWhere ( ) ; PreparedStatement ps = null ; // System.out.println("delete string "+deleteString); try { // fill the question marks ps = cConn . prepareStatement ( deleteString ) ; ps . clearParameters ( ) ; int i ; for ( int j = 0 ; j < primaryKeys . length ; j ++ ) { ps . setObject ( j + 1 , resultRowPKs [ aktRowNr ] [ j ] ) ; } // end of for (int i=0; i<primaryKeys.length; i++) ps . executeUpdate ( ) ; } catch ( SQLException e ) { ZaurusEditor . printStatus ( "SQL Exception: " + e . getMessage ( ) ) ; return 0 ; } finally { try { if ( ps != null ) { ps . close ( ) ; } } catch ( SQLException e ) { } } // delete the corresponding primary key values from resultRowPKs numberOfResult -- ; for ( int i = aktRowNr ; i < numberOfResult ; i ++ ) { for ( int j = 0 ; j < primaryKeys . length ; j ++ ) { resultRowPKs [ i ] [ j ] = resultRowPKs [ i + 1 ] [ j ] ; } } // there are the following outcomes after deleting aktRowNr: /* A B C D E F no rows left J N N N N N one row left - J N J N N deleted row was the last row - J J N N N deleted row was the pre-last - - - - J N first D X + D + * . D X X D D . D X + last X new numberOfResult 0 1 2 1 2 2 old aktRowNr 0 1 2 0 1 0 D - deleted row X - any one row + - one or more rows * - zero or more rows */ // A. return to the search panel and tell 'last row deleted' on the status line // B. show the previous row and disable previous button // C. show the previous row as akt row // D. show akt row and disable next button // E. show akt row and disable next button // F. show akt row // these actions reduce to the following actions for ZaurusEditor: // 1. show search panel // 2. disable previous button // 3. disable next button // 4. do nothing // and 1,2,3,4 are the possible return codes int actionCode ; if ( numberOfResult == 0 ) { // case A actionCode = 1 ; ZaurusEditor . printStatus ( "Last row was deleted." ) ; return actionCode ; } else if ( numberOfResult == aktRowNr ) { // B or C // new aktRow is previous row aktRowNr -- ; if ( aktRowNr == 0 ) { // B actionCode = 2 ; } else { // C actionCode = 4 ; } // end of if (aktRowNr == 0) } else { // D, E, F if ( numberOfResult >= 2 && aktRowNr < numberOfResult - 1 ) { // F actionCode = 4 ; } else { actionCode = 3 ; } // end of else } this . showAktRow ( ) ; ZaurusEditor . printStatus ( "Row was deleted." ) ; return actionCode ; }
delete current row answer special action codes see comment below