import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;

public class adresdegistir implements ActionListener {
   private adrespanel fields;
   private JTextArea output;
   private Connection connection;

   public adresdegistir( Connection c, adrespanel f, JTextArea o )
   {
      connection = c;
      fields = f;
      output = o;
   }

   public void actionPerformed( ActionEvent e )
   {
try {
         Statement statement = connection.createStatement();
          if ( ! fields.id.getText().equals( "" ) )
         {
          String a[]=new String[14];
          a[0]=fields.isim.getText();
          a[1]=fields.soyisim.getText();
          a[2]=fields.adres.getText();
          a[3]=fields.ilce.getText();
          a[4]=fields.il.getText();
          a[5]=fields.postakodu.getText();
          a[6]=fields.ulke.getText();
          a[7]=fields.emailadresi.getText();
          a[8]=fields.telefonev.getText();
          a[9]=fields.telefonis.getText();
          a[10]=fields.telefoncep.getText();
          a[11]=fields.faks.getText();
          a[12]=fields.webadresi.getText();
          a[13]=fields.evadresi.getText();
          for(int i=0;i<a.length;i++)
            {if(a[i].equals("")) a[i]=" ";}
         if ( !a[1].equals( "" ) &&
              !a[0].equals( "" ) )
         {
            String query = "UPDATE adres SET ";
            query+="isim ='";query+=fields.isim.getText();
            query+="',soyisim ='";query+=fields.soyisim.getText();
            query+="',adres ='";query+=fields.adres.getText();
            query+="',ilce ='";query+=fields.ilce.getText();
            query+="',il ='";query+=fields.il.getText();
            query+="',postakodu ='";query+=fields.postakodu.getText();
            query+="',ulke ='";query+=fields.ulke.getText();
            query+="',emailadresi ='";query+=fields.emailadresi.getText();
            query+="',telefonev ='";query+=fields.telefonev.getText();
            query+="',telefonis ='";query+=fields.telefonis.getText();
            query+="',telefoncep ='";query+=fields.telefoncep.getText();
            query+="',faks='";query+=fields.faks.getText();
            query+="',webadresi ='";query+=fields.webadresi.getText();
            query+="',evadresi ='";query+=fields.evadresi.getText();
            query+="' WHERE ID=";query+=fields.id.getText();
            output.append( "\nquery gönderiliyor : " +
            connection.nativeSQL( query ) + "\n" );
            int result = statement.executeUpdate( query );
            if ( result == 1 )
               output.append( "\nkayıt başarıyla değiştirildi \n" );
            else {
               output.append( "\nkayit değiştirme işlemi başarılamadı\n" );
               fields.isim.setText("");
               fields.soyisim.setText("");
               fields.adres.setText("");
               fields.ilce.setText("");
               fields.il.setText("");
               fields.postakodu.setText("");
               fields.ulke.setText("");
               fields.emailadresi.setText("");
               fields.telefonev.setText("" );
               fields.telefonis.setText("");
               fields.telefoncep.setText("");
               fields.faks.setText("");
               fields.webadresi.setText("");
               fields.evadresi.setText("");
                 }
            statement.close();
         }   //
         } //end of if
         else
            output.append( "\nsadece mevcut olan kayıtları değiştirebilirsiniz\n" );
      }
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
         output.append( sqlex.toString() );
      }
   }
}

