import java.sql.*;
import java.net.*;
import java.io.*;
import java.lang.*;
import java.util.*;

public class crewCoverage {
	
	
	public static void main (String[] args) throws Exception
       {
       	
       	
       	
       	String primo,secondo;
		secondo = null;
		String year=null;
		
       	String[]res;

        FileWriter fi = new FileWriter("G:\\Documents and Settings\\cristiano\\Desktop\\tesina seminario\\tesina\\finalScripts\\crewcoverage.sql");
		PrintWriter out=new PrintWriter(fi);
	  
       	FileReader f = new FileReader("G:\\Documents and Settings\\cristiano\\Desktop\\tesina seminario\\tesina\\file IMDB\\complete-crew.txt");
        BufferedReader filebuf = new BufferedReader(f); 
      

        String nextStr;
        nextStr = filebuf.readLine();
        
			
		while (!nextStr.equals("CREW COVERAGE TRACKING LIST")){
		nextStr = filebuf.readLine();
        }	
			
		nextStr = filebuf.readLine();
        nextStr = filebuf.readLine();
        	
							
			
			
     	while (nextStr!=null){
     		try{
 
         
        if (nextStr.equals("-----------------------------------------------------------------------------")){
        	System.out.println("Crew inseriti nel db");
        	break;
        }
        	
         nextStr=nextStr.replace("'","");
        	
         res=nextStr.split("\t");
        
          for (int x=1; x<res.length; x++){
         
          if (!res[x].equals("\t")){
          	secondo= res[x];
          }
        
      	 }
       	
      
       	
        primo=res[0];
         if (primo.contains("(")){
    		int inizio2=primo.indexOf("(");
    		int fine=primo.indexOf(")");
    		year=primo.substring(inizio2+1,fine);
    		primo=primo.substring(0,inizio2);     
    	}
    	
    	else {
    		year=null;
    	}
    	
    	
		/*    	
        System.out.println("***************");
        System.out.println(primo);
      	System.out.println(secondo);
        */
        
        		
    			    
  				
  					out.println("UPDATE movies SET crewcoverage='"+secondo+"' WHERE title='"+primo+"' and year='"+year+"';");
		
   		
      
       
       
       nextStr = filebuf.readLine();// legge una riga del file 
    
		}
		catch(NullPointerException e){
 			break;
 			
 		}
		    
    
           }
           
       
       filebuf.close();  // chiude il file    
       out.close();  
       }
		
		
		
	}
	