Error while exporting structure in 'jchem Exporter' .Net API

User 73ad691ca3

20-08-2012 13:29:19

 

Hi,


We are getting error while exporting structures from "Jchem Exporter" using "JChem .NET API 5.10.3.437".


Actually we have implemented Exporting structures with data from structure table and other data table, this is working fine in java.


Our requirement is to query structure and other table data, and export the data 'to string' or 'write to a file', This has to be done using Jchem for .NET API.


But we want the exporting functionality in dotnet using "Jchem for .Net API".


We had written the below code for dotnet. And while we run the code in dotnet we are getting the below error.


Error: Unexpected error during DB export init: null


Below is the code we are using:


//////////////////////////////////////////////////////////////////////////


using System;
using System.Text;
using System.Data;
using System.Configuration;
using java.sql;
using chemaxon.util;
using chemaxon.struc;
using chemaxon.jchem.db;
using chemaxon.sss.search;
using java.io;


namespace JChemBaseSearch
{


    /// <summary>
    /// DataAccess class using JDBC driver
    /// </summary>
    public static class DataAccess
    {
        private static ConnectionHandler getConnectionHandler()
        {
            string url = "jdbc:oracle:thin:@dboracle01:1521:jchem"; //read configuration settings from App.config
            string username = "jcm";
            string password = "jcm";


            try
            {
                DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                Connection conn = DriverManager.getConnection(url, username, password);


                ConnectionHandler ch = new ConnectionHandler();
                ch.setConnection(conn);


                return ch;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }      



        public static void ExportData()
        {
            string sdfResult = string.Empty;
            string qry = "select t.CD_STRUCTURE, t.CD_ID from test t";// where t.CD_ID = 512";
            string outputcolnames = "CD_ID:CD_ID";


            OutputStream outs = null;


            try
            {
                Exporter exp = new Exporter();
                exp.setConnectionHandler(getConnectionHandler());
                exp.setSelectStatement(qry);
                exp.setOutputFieldConversion(outputcolnames);


                /*
                OutputStream outs = new OutputStream()
                {
                    private StringBuilder string = new StringBuilder();
                    //@Override        
                        public void write(int b) throws IOException
                        {            
                            this.string.append((char) b );
                        }         
                        //Netbeans IDE automatically overrides this toString()        
                        public String toString(){            
                            return this.string.toString();        
                        }   
                };
                 */


                java.io.File file = new java.io.File("c:/test/sdfTest.sdf");
                file.getParentFile().mkdirs();
                outs = new java.io.FileOutputStream(file);


                exp.setOutputStream(outs);
                exp.setFormat(1);
                exp.writeAll();


            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                outs.flush();
                outs.close();
            }


        }



    }


}


/////////////////////////////////////////////////////////////////////////////


Please let us know why the jchem throws error.


Please resolve this issue asap.


Please let us know if you need any other information regarding this.


Thanks & Regards,


Senthil kumar vijai.


User 73ad691ca3

21-08-2012 10:02:08

Hi,


Is there any update on this exporting structures to sdf file issue in jchem .net api.


Have you figured out the issue.


Thanks & regards,


Senthil kumar vijai.


 

ChemAxon eb65a25631

21-08-2012 13:19:08

Hi,


Well, the code runs OK for me.


Though it has to be extended by a call to


exp.setTableName(...);


 


Checking it with 5.10...


Regards,


Andras

ChemAxon eb65a25631

21-08-2012 13:49:33

I tried it with the latest 5.10 version: 5.10.3.745.


The same (fixed) code works with it.


Are you sure you added all the necessary references? (Involving the JDBCDrivers subfolder in the installation directory)


 


Regards,


Andras

User 73ad691ca3

22-08-2012 12:32:18

Dear Andras,


Good Day,


Thanks for your quick reply,


Thanks for your help in solving the issue for "exporting of structure data based on query".  


We added exp.setTableName(...) in the code, as you mentioned, So the structure data is exporting.


But in 'jchem for java' this line of code was not included, even though it was working fine.


we will get back to you, incase if we have any issues in exporting structures using jchem .Net API.


Below is the code to "export structures based on the select query using jchem .net api".


Please change the parameters according to your requirement and development environment.


/////////////////////////////////
using System;
using System.Text;
using System.Data;
using System.Configuration;
using java.sql;
using chemaxon.util;
using chemaxon.struc;
using chemaxon.jchem.db;
using chemaxon.sss.search;
using java.io;


namespace JChemBaseSearch
{


    /// <summary>
    /// DataAccess class using JDBC driver
    /// </summary>
    public static class Exporter1
    {
        private static ConnectionHandler getConnectionHandler()
        {
            string url = "jdbc:oracle:thin:@dboracle01:1521:jchem"; //read configuration settings from App.config
            string username = "jcm";
            string password = "jcm";


            //string url = ConfigurationManager.AppSettings["url"];//jdbc:oracle:thin:@dbora:1521:jchem
            //string username = ConfigurationManager.AppSettings["username"];//jcm
            //string password = ConfigurationManager.AppSettings["password"];//jcm


            try
            {
                DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                Connection conn = DriverManager.getConnection(url, username, password);


                ConnectionHandler ch = new ConnectionHandler();
                ch.setConnection(conn);


                return ch;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        public static void ExportData()
        {
            string sdfResult = string.Empty;
            string qry = "select t.CD_STRUCTURE, t.CD_ID, b.BATCH_NUMBER from test t inner join batch_details b on t.cd_id = b.cd_id where t.CD_ID = 512 or t.CD_ID = 505";//query with filter/order by
            string outputcolnames = "CD_ID:CD_ID|BATCH_NUMBER:BATCH_NUMBER";
            string jchemStructureTableName = "test";//table which is used to store structure


            OutputStream outs = null;


            try
            {
                Exporter exp = new Exporter();
                exp.setConnectionHandler(getConnectionHandler());
                exp.setSelectStatement(qry);


                java.io.File file = new java.io.File("c:/test/sdfTest_1_1.sdf");
                file.getParentFile().mkdirs();
                outs = new java.io.FileOutputStream(file);


                exp.setTableName(jchemStructureTableName);
                exp.setOutputStream(outs);
                exp.setFormat(2);//sdf format
                exp.writeAll();


            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                outs.flush();
                outs.close();
            }


        }



    }


}


///////////////////////////////


 


Thanks and Regards,


D.Senthil kumar vijai.