
import java.io.*;


public class CreationSQL {

	public CreationSQL() throws IOException {
	{

			String line = "";
			String fic = "";
			BufferedReader bufR;
			BufferedWriter bufW;
			String debut="";
			int cpt=0;
			boolean id=false;

			try {

					bufR = new BufferedReader(new FileReader(new File("InsertIntoBDD.txt")));
					bufW = new BufferedWriter(new FileWriter(new File("remplissageBDD.sql")));

					if (bufR == null)
					{
						throw new FileNotFoundException("fichier non trouvé: "+ fic);
					}
					do
					{
						line = bufR.readLine();
						if (line != null)
						{
							if(line.indexOf(":")!=-1)
							{
								String[]tab2 = line.split(":");
								debut ="INSERT INTO "+tab2[0]+"("+tab2[1]+") VALUES ";
								cpt=0;
								if(line.indexOf("id")!=-1)
								{
									System.out.println("test2");
									id=true;
								}
								else
								{
									id=false;
								}
							}
							else
							{
								System.out.println("id:"+id);
								if(id==true)
								{
									cpt++;
									bufW.write(debut+"("+cpt+","+line+");");
									bufW.write("\r\n");
								}
								else
								{
									bufW.write(debut+"("+line+");");
									bufW.write("\r\n");
								}
							}
						}

					} while (line!=null);

					bufR.close();
					bufW.close();
					System.out.println("\n");
				}
				catch (FileNotFoundException e)
				{
					System.out.println(e.getMessage());
				}
				catch (IOException e)
				{
					System.out.println(e.getMessage());
				}
	}

	}

	public static void main(String [] args)throws IOException
	{
		CreationSQL c = new CreationSQL();
	}

}

