hello ,
I'm studying engineering school, I have to make a java method that allows to import the xml file, and put in a database so it ca not exist creates it, and after you optimize, I do this code, but my placement tutor does not agree, is that you can help me please.
public void importerImpl(File dossierContenantLesXmls, String nomDeLaBaseDeDonnee, boolean ecraserDb) {
final Context context = null; Parser parser = null; File[] listefichierXml = dossierContenantLesXmls.listFiles();
/*tester si la base de donnée exste on l'ouvre sinon on la crée pour le test d'existence il y a ausi cette fonction à voir avec Bruno con.getDatabaseConnection(nomDeLaBaseDeDonnee); */
System.out.println("------------------ opens an existing database or creates a new one------------------ "); if(context.soptions.dbexists("nomDeLaBaseDeDonnee")) { new Open ("nomDeLaBaseDeDonnee"); }else { try { Data data = CreateDB.create( nomDeLaBaseDeDonnee, parser, context, null); new Open ("nomDeLaBaseDeDonnee"); } catch (IOException ex) { ex.getCause(); } } // parcourir une liste de fichier Xml puis ajouter chaque fichier a basex for (int i=0;i<=listefichierXml.length;i++){ new Add("listefichierXml[i].getAbsolutePath()"); } new Optimize(); context.close(); } }
Hello,
please be much more specific what you want to do and what does not work. That your tutor does not agree is not a proper problem description - Why does he not agree, what does not work as expected?
However, I seriously doubt you ever attempted to run this code sample, so this should be the first thing to do. If you do, you should notice at least compiler warnings as for example your statement "final Context context = null;" is not really useful as it initializes the variables context with null and can not be changed. So your next usage of this variable will fail. Also, you always have to execute database commands against a database context. Please take a look at our examples, e.g. at https://github.com/BaseXdb/basex/blob/master/basex-examples/src/main/java/or...
Cheers, Dirk
On 07/23/2015 01:52 PM, Yassine Hamdouni wrote:
hello ,
I'm studying engineering school, I have to make a java method that allows to import the xml file, and put in a database so it ca not exist creates it, and after you optimize, I do this code, but my placement tutor does not agree, is that you can help me please.
public void importerImpl(File dossierContenantLesXmls, String nomDeLaBaseDeDonnee, boolean ecraserDb) {
final Context context = null; Parser parser = null; File[] listefichierXml = dossierContenantLesXmls.listFiles(); /*tester si la base de donnée exste on l'ouvre sinon on la
crée pour le test d'existence il y a ausi cette fonction à voir avec Bruno con.getDatabaseConnection(nomDeLaBaseDeDonnee); */
System.out.println("------------------ opens an existing
database or creates a new one------------------ "); if(context.soptions.dbexists("nomDeLaBaseDeDonnee")) { new Open ("nomDeLaBaseDeDonnee"); }else { try { Data data = CreateDB.create( nomDeLaBaseDeDonnee, parser, context, null); new Open ("nomDeLaBaseDeDonnee"); } catch (IOException ex) { ex.getCause(); } } // parcourir une liste de fichier Xml puis ajouter chaque fichier a basex for (int i=0;i<=listefichierXml.length;i++){ new Add("listefichierXml[i].getAbsolutePath()"); } new Optimize(); context.close(); } }
-- cordialement
HAMDOUNI Yassine
basex-talk@mailman.uni-konstanz.de