public boolean saveChanges ( ) { // the initial settings of the textfields counts with one // so a real change by the user needs as many changes as there are columns // System.out.print("Anderungen in den Feldern: "); // there are changes to the database // memorize all columns which have been changed int [ ] changedColumns = new int [ columns . length ] ; int countChanged = 0 ; // build the update string String updateString = "" ; for ( int i = 0 ; i < columns . length ; i ++ ) { if ( komponente [ i ] . hasChanged ( ) ) { if ( updateString != "" ) { updateString += ", " ; } updateString += columns [ i ] + "=?" ; changedColumns [ countChanged ++ ] = i ; } } // end of for (int i=0; i<columns.length; i++) if ( countChanged > 0 ) { updateString = "UPDATE " + tableName + " SET " + updateString + this . generatePKWhere ( ) ; PreparedStatement ps = null ; // System.out.println("update "+updateString); try { // fill the question marks ps = cConn . prepareStatement ( updateString ) ; ps . clearParameters ( ) ; int i ; for ( i = 0 ; i < countChanged ; i ++ ) { ps . setObject ( i + 1 , komponente [ changedColumns [ i ] ] . getContent ( ) ) ; // System.out.print(" changed feld "+komponente[changedColumns[i]].getContent()); } // end of for (int i=0; i<countChanged; i++) // System.out.println(); for ( int j = 0 ; j < primaryKeys . length ; j ++ ) { ps . setObject ( i + j + 1 , resultRowPKs [ aktRowNr ] [ j ] ) ; } // end of for (int i=0; i<primaryKeys.length; i++) ps . executeUpdate ( ) ; ZaurusEditor . printStatus ( "changed row was saved to table " + tableName ) ; return true ; } catch ( SQLException e ) { ZaurusEditor . printStatus ( "SQL Exception: " + e . getMessage ( ) ) ; return false ; } finally { try { if ( ps != null ) { ps . close ( ) ; } } catch ( SQLException e ) { } } } else { // System.out.println("no changes"); return true ; } // end of if (changed) }
answer true if the update succeeds