import java.sql.*;
 
public class H9O2 
{
  public static void main(String[] args)
  {
    String url="jdbc:odbc:h9o2";
    Connection con;
    Statement stmt;
    String query2="select AVG(SAYI) as T from H9O2";
    String query1="select SAYI from H9O2";
    try
    {
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
    } 
    catch(java.lang.ClassNotFoundException e)
    { System.err.println(e.getMessage()); }
    try
    {
     con=DriverManager.getConnection(url);
     stmt=con.createStatement();
     ResultSet rs= stmt.executeQuery(query1);
     int j=0;
     double toplam=0;
     while (rs.next())
     {
       double sayi=  rs.getDouble("SAYI");
       toplam+=sayi;
       System.out.println("Sayi("+(j++)+") = "+sayi);
     }
     System.out.println("metod 1 ortalamalar query dilinde hesaplandi");
     rs= stmt.executeQuery(query2);
     while (rs.next())
     {
       double i=  rs.getDouble("T");
       System.out.println("Ortalama = "+i);
     }
     System.out.println("metod 2 ortalamalar java dilinde hesaplandi");
     double ortalama=toplam/j;
     System.out.println("metod 2 ortalama : "+ortalama);
     stmt.close();
     con.close();
    }
    catch (SQLException e)
    {
     System.err.println(e.getMessage()); 
    } //catch  
  } //main
} //class
