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

public class adresgir implements ActionListener {
   private adrespanel fields;
   private JTextArea output;
   private Connection connection;
   public adresgir( Connection c, adrespanel f,
                     JTextArea o )
   {
      connection = c;
      fields = f;
      output = o;
   }

   public void actionPerformed( ActionEvent e )
   {
      try {
         Statement statement = connection.createStatement();
          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 ( !fields.soyisim.getText().equals( "" ) &&
              !fields.isim.getText().equals( "" ) ) {
            String query = "INSERT INTO adres (" +
               "isim, soyisim, adres, ilce, " +
               "il, postakodu, ulke, " +
               "emailadresi, telefonev, telefonis" +
               ",telefoncep, faks, webadresi,evadresi ) VALUES ('";
               query+=a[0]+ "', '";
                query+=a[1]+ "', '" ;
                query+=a[2]+ "', '" ;
                query+=a[3]+ "', '" ;
                query+=a[4]+ "', '" ;
                query+=a[5]+ "', '" ;
                query+=a[6]+ "', '" ;
                query+=a[7]+ "', '" ;
                query+=a[8]+ "', '" ;
                query+=a[9]+ "', '" ;
                query+=a[10]+ "', '" ;
                query+=a[11]+ "', '" ;
                query+=a[12]+ "', '" ;
                query+=a[13]+ "')";
            output.append( "\nSQL query gönderiliyor: " +
                           connection.nativeSQL( query )
                           + "\n" );
            int result = statement.executeUpdate( query );

            if ( result == 1 )
               output.append( "\nQuery başarıyla çalıştı\n" );
            else {
               output.append( "\nQuery hata verdi\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("");
            }
         }
         else
            output.append( "\nen azından isim ve soy isim girin ve sonra  " +
                           "ekle dugmesine basın\n" );
         statement.close();
      }
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
         output.append( sqlex.toString() );
      }
   }
}

