Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.bowprog.sql.constructeur; import com.bowprog.sql.MySQLContext; import com.bowprog.sql.constructeur.Table; import java.io.File; import java.io.FileFilter; import java.io.FileNotFoundException; import java.io.FileReader; import java.sql.SQLException; import java.sql.Statement; import java.util.Collection; import java.util.logging.Level; import java.util.logging.Logger; import org.json.simple.JSONObject; import org.json.simple.JSONValue; /** * * @author micmonay */ public class CreateDataBase { private final File dirStructure; private final MySQLContext mySQLContext; private Statement statement; /** * Cre la base de donnes en rapport avec les fichiers * @param dirStructure * @param mySQLContext */ public CreateDataBase(File dirStructure, MySQLContext mySQLContext) throws SQLException { this.dirStructure = dirStructure; this.mySQLContext = mySQLContext; statement = mySQLContext.getStatement(); } /** * lance la cration */ public void launch() { File[] listFile = dirStructure.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.getName().contains(".json")) { return true; } return false; } }); for (File file : listFile) { fileRead(file); } } private void fileRead(File file) { try { Table table = new Table(statement); JSONObject obj = (JSONObject) JSONValue.parse(new FileReader(file)); table.appliqueJSON(obj); } catch (FileNotFoundException ex) { Logger.getLogger(CreateDataBase.class.getName()).log(Level.SEVERE, null, ex); } } }