Hi,

I have a lot of troubles when I try to create a text datasource from Java. The database got created but the table (who should be based on the CSV file) never appears. My test CSV file has only 3 lines and it correctly formatted. I was thinking that maybe it's a bug in OOo for OS X but I tried on RedHat ES 3 and I have the same problem. The code :

-------------------------
   public void createNewDataSource() {

        mDataSourceDir = "/Users/probert/Travail/OpenOffice/";
        mTableName = "test.csv";

        try{
                        
XSingleServiceFactory factory = (XSingleServiceFactory) UnoRuntime.queryInterface(XSingleServiceFactory.class, mxMSF.createInstance("com.sun.star.sdb.DatabaseContext"));

XNamingService xServ = (XNamingService) UnoRuntime.queryInterface(XNamingService.class, factory);

                        Object dataSource = factory.createInstance();

XDocumentDataSource xDocumentDataSource = (XDocumentDataSource) UnoRuntime.queryInterface(XDocumentDataSource.class, dataSource);

XOfficeDatabaseDocument xDatabaseDocument = xDocumentDataSource.getDatabaseDocument();

XStorable store = (XStorable) UnoRuntime.queryInterface(XStorable.class, xDatabaseDocument); XModel model = (XModel) UnoRuntime.queryInterface(XModel.class, xDatabaseDocument); String storeFileName = "file:///Users/probert/Travail/OpenOffice/test.odb";
                        store.storeAsURL(storeFileName, model.getArgs());

                        xServ.registerObject(mDataSourceName, dataSource);      
                

XPropertySet props = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, dataSource);

                        props.setPropertyValue("URL", "sdbc:flat:" + 
mDataSourceDir);
                        String tableFilter[] = new String[1];
                        tableFilter[0] = new String(mTableName);

                        props.setPropertyValue("TableFilter", tableFilter);

                        PropertyValue[] cProps = new PropertyValue[8];
                        cProps[0] = new PropertyValue();
                        cProps[0].Name = "Extension";
                        cProps[0].Value = "csv";
                        cProps[1] = new PropertyValue();
                        cProps[1].Name = "Charset";
                        cProps[1].Value = "windows-1252";                     
                        cProps[2] = new PropertyValue();
                        cProps[2].Name = "FixedLength";
                        cProps[2].Value = "True";                     
                        cProps[3] = new PropertyValue();                        
                        cProps[3].Name = "HeaderLine";
                        cProps[3].Value = "True";                     
                        cProps[4] = new PropertyValue();
                        cProps[4].Name = "FieldDelimiter";
                        cProps[4].Value = ",";
                        cProps[5] = new PropertyValue();
                        cProps[5].Name = "StringDelimiter";
                        cProps[5].Value = "\"";
                        cProps[6] = new PropertyValue();
                        cProps[6].Name = "DecimalDelimiter";
                        cProps[6].Value = ".";
                        cProps[7] = new PropertyValue();
                        cProps[7].Name = "ThousandDelimiter";
                        cProps[7].Value = ";";                                  
      
                        props.setPropertyValue("Info", cProps);       
                        props.setPropertyValue("User","probert");
                        
                        store.store();
                                        
        }
        catch(Exception e) {
            System.err.println ("Error creating data source: " + e);
                        e.printStackTrace();
        }
    }
-------------------------

BTW, do I can read the properties of a working text datasource ? I want to compare properties from the two databases but I can't find which method should I use to see the properties of an opened database.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to