	   import java.io.*;
	   import java.util.*;
	   import javax.swing.*;
       import javax.swing.table.*;
       import java.awt.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

class data
	{
	public double x[];	
	public data(double[] xi)
	{
	int n=xi.length;
	x=new double[n];
	for(int i=0;i<n;i++) {x[i]=xi[i];}
	}	
	public String toString() {return ""+x[0]+" "+x[1];}
	}
		        
public class H9Ex1
{	
     public static double[][] inputdouble(String filename) throws IOException
     {
	 //reading double values from one line of data    
	 BufferedReader fin=new BufferedReader(new FileReader(filename));
     double a[][]=inputdouble(fin);
     return a;
     }
     
    public static double[][] inputdouble(BufferedReader fin) throws IOException
    {
	 ArrayList<data> a=new ArrayList<data>();
	 int mmax=0;
	 double b[][];
	 int n=0,m=0;
	 String s1="";	 
	 try{
       while(fin!=null)
       { s1=fin.readLine();
       if(s1==null)break;
         StringTokenizer token=new StringTokenizer(s1);
         m=token.countTokens();
         if(m>mmax) mmax=m;
         double aa[]=new double[m];
         int j=0;           
         while(token.hasMoreTokens())
         { Double ax=new Double(token.nextToken());
           aa[j++]=ax.doubleValue();
         }
         data vx=new data(aa);
         a.add(vx);
       n++;
	   }
       } catch(EOFException e_eof)
          {
          //close ffile
          try{fin.close();
      } 
      catch(NullPointerException e) {}   
      catch(IOException e)
             {
             System.err.println("Error Closing File\n"+e.toString());
             System.exit(1);
             }
          } //End of EOFException
     b=new double[n][mmax];
     int k=0;
     Iterator i=a.iterator();
     while(i.hasNext()) {data vx=(data)i.next();b[k++]=vx.x;}
     return b;
     }     
          
     public static String toString(double a[][])
     {
	 String s="";
     for(int i=0;i<a.length;i++)
     {
	 for(int j=0;j<a[0].length;j++)    
     {s+="a["+i+"]["+j+"] = "+a[i][j]+" ";}
     s+="\n";
     }
     return s;
	 }
                  	
public static void main(String args[]) throws IOException,ClassNotFoundException
{	
  String s1="a.txt";
  File f=new File(s1);
  BufferedReader fin=new BufferedReader(new FileReader(f));
  double number[][]=inputdouble(fin);
  JOptionPane.showMessageDialog(null,toString(number),"sequential file reading",JOptionPane.PLAIN_MESSAGE);
    // load the sqlite-JDBC driver using the current class loader
    Class.forName("org.sqlite.JDBC");   
    Connection connection = null;
    try
    {
      // create a database connection
      connection = DriverManager.getConnection("jdbc:sqlite:H9.db");
      Statement statement = connection.createStatement();
      statement.setQueryTimeout(30);  // set timeout to 30 sec.      
      statement.executeUpdate("drop table if exists H9Ex1");
      statement.executeUpdate("create table H9Ex1(x double, y double,y2 double)");
      String s2="";
      for(int i=0;i<number.length;i++)
      {
      s2=""+number[i][0]+","+number[i][1]+","+null;
      statement.executeUpdate("insert into H9Ex1 values("+s2+");");
      }
      statement.executeUpdate("update H9Ex1 set y2=y*y;");     
      ResultSet rs = statement.executeQuery("select * from H9Ex1");
      while(rs.next())
      {
        // read the result set
        double x=rs.getDouble("x");
        double y=rs.getDouble("y");
        double y2=rs.getDouble("y2");
        System.out.println(" x = " + x+" y = "+y+" y2 = "+y2);
      }
    }
    catch(SQLException e)
    {
      // if the error message is "out of memory", 
      // it probably means no database file is found
      System.err.println(e.getMessage());
    }
    finally
    {
      try
      {
        if(connection != null)
          connection.close();
      }
      catch(SQLException e)
      {
        // connection close failed.
        System.err.println(e);
      }
    }
}
}
