These classes provide solutions for importing/exporting structures into/from JChem database tables.

    Contents

    Importer

    Structure files can be imported into the database using chemaxon.jchem.db.importer.

    Java example:

            Importer importer = new Importer();
    
            importer.setConnectionHandler(connHandler);
            importer.setInput(fileName);
            importer.setTableName(tableName);
            importer.setLinesToCheck(numOfLines);
            importer.setHaltOnError(false);
            importer.setDuplicatesAllowed(true);
    
            System.out.println("Collecting file information ...");
            importer.init();
            System.out.println("Done.");
    
            // Skip "offset" number of structures from the beginning of file
            System.out.println("Skipping " + offset + " structures ...");
            importer.skip(offset);
            System.out.println("Done.");
    
            // Perform importing
            System.out.println("Importing structures from " + filename + " ...");
            int imported = importer.importMols();
            System.out.println("Done.");
            System.out.println("Imported " + imported + " structures");

    Note: For the sake of readability, try/catch is omitted in this example.

    Using an InputSream object as data source

    You may also use InputStream instead of File in the constructor of Importer. The only possible drawback may be that a given number of lines (linesToCheck parameter in the example) will be buffered in memory in that case, so this value shouldn't be excessively high.

    Exporter

    With the use of chemaxon.jchem.db.exporter, structure table data can be exported into files or any OutputStream objects.

    Java example:

            int format = Transfer.SMILES;
            OutputStream os = new FileOutputStream(new File(fileName));
            Exporter ex=new Exporter();
            ex.setConnectionHandler(connHandler);
            ex.setTableName(tableName);
            ex.setFieldList(fieldString);
            ex.setOutputStream(os);
            ex.setFormat(format);
            ex.setDefaults(true);               // only exporting default fields
    
            System.out.println("Exporting structures into " + fileName + " ...");
            int written = ex.writeAll();       // writing file in one step
            System.out.println(written+" molecules were exported.");

    Molecules can be written one-by-one, by changing the end of the code to the following:

            int count=0;
            while (ex.writeNext()) {
                count++;
                System.out.println("Molecule number " + count + " exported.");
            }

    Note: For the sake of readability, try/catch is omitted in this example.

    Custom select statement

    Use Exporter.setSelectStatement() to specify a custom select statement as the basis of the export. This enables

    • exporting related data from other tables together with the structures

    • ordering the structures with an ORDER BY clause