// Class UpdateRecord definition
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;

public class AtualizandoRegistro implements ActionListener {
   private ScrollingPanel fields;
   private JTextArea output;
   private Connection connection;

   public AtualizandoRegistro( Connection c, ScrollingPanel f,
                        JTextArea o )
   {
      connection = c;
      fields = f;
      output = o;
   }

   public void actionPerformed( ActionEvent e )
   {
      try {
         Statement statement = connection.createStatement();

         if ( ! fields.clncodg.getText().equals( "" ) ) {
            String query = "UPDATE TBcliente SET " +
                   "clcdesc='" + fields.clcdesc.getText() + 
                   "', clyrend='" + fields.clyrend.getText()+ 
                   "' WHERE clncodg=" + fields.clncodg.getText();
                   output.append( "\nEnviando query: " + 
                   connection.nativeSQL( query ) + "\n" );

            int result = statement.executeUpdate( query );
            
            if ( result == 1 )
               output.append( "\nAtualizado com sucesso\n" );
            else {
               output.append( "\nFalha na atualizacao\n" );
               fields.clcdesc.setText( "" );
               fields.clyrend.setText( "" );
            }

            statement.close();
         }
         else 
            output.append( "\nVoce so pode atualizar um" +
                           "registro que existe. Use Procurar para " +
                           "localizar o rengistro, entao " +
                           "modifique a informacao e " +
                           "precione Atualizar.\n" );
      }
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
         output.append( sqlex.toString() );
      }
   }
}

/**************************************************************************
 * (C) Copyright 1999 by Deitel & Associates, Inc. and Prentice Hall.     *
 * All Rights Reserved.                                                   *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/
