OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Can't create table with Java code

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
probert
General User
General User


Joined: 13 Apr 2006
Posts: 16

PostPosted: Wed Apr 26, 2006 10:04 am    Post subject: Can't create table with Java code Reply with quote

Hi,

I'm trying to get the MailMeger code snippet to work with OOo 2. Now I can create a database but I can't create the table inside it. When I open the created database in OOo Base, I don't see any tables in it, and I can't create a table in OOo Base either.

This is the code :

Code:

    public void createNewDataSource() {

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

         // Register it with the database context
         XNamingService xServ = (XNamingService) UnoRuntime.queryInterface(XNamingService.class, factory);

         // Use the XSingleServiceFactory interface to instantiate an
         // empty data source
         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());

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

         props.setPropertyValue("URL", "sdbc:flat:file:///" + "/Users/probert/Travail/OpenOffice");
         String tableFilter[] = new String[1];
         tableFilter[0] = new String("test");

         props.setPropertyValue("TableFilter", tableFilter);

         PropertyValue[] cProps = new PropertyValue[9];
         cProps[0] = new PropertyValue();
         cProps[0].Name = "Extension";
         cProps[0].Value = "csv";
         cProps[1] = new PropertyValue();
         cProps[1].Name = "FieldDelimiter";
         cProps[1].Value = ",";
         cProps[2] = new PropertyValue();
         cProps[2].Name = "StringDelimiter";
         cProps[2].Value = "\"";
         cProps[3] = new PropertyValue();
         cProps[3].Name = "DecimalDelimiter";
         cProps[3].Value = "";
         cProps[4] = new PropertyValue();
         cProps[4].Name = "ThousandDelimiter";
         cProps[4].Value = ".";
         cProps[5] = new PropertyValue();
         cProps[5].Name = "CharSet";
         cProps[5].Value = "1";
         cProps[6] = new PropertyValue();
         cProps[6].Name = "EnableSQL92Check";
         cProps[6].Value = "False";   
         cProps[7] = new PropertyValue();
         cProps[7].Name = "PreferDosLikeLineEnds";
         cProps[7].Value = "True";   
         cProps[8] = new PropertyValue();
         cProps[8].Name = "HeaderLine";
         cProps[8].Value = "True";            
         props.setPropertyValue("Info", cProps);

         xServ.registerObject(mDataSourceName, dataSource);         
        }
        catch(Exception e) {
            System.err.println ("Error creating data source: " + e);
        }
Back to top
View user's profile Send private message
starm
General User
General User


Joined: 24 Apr 2006
Posts: 8

PostPosted: Thu Apr 27, 2006 12:08 am    Post subject: Reply with quote

The flat base is in read only mod so you can't create table. To see any table, check in the options where the base search the csv files. If there's any csv files in this repertory, the tables are automatically created.

(Sorry for the bad english ^^)

Starm
Back to top
View user's profile Send private message
probert
General User
General User


Joined: 13 Apr 2006
Posts: 16

PostPosted: Thu Apr 27, 2006 5:50 am    Post subject: Reply with quote

I do have one CSV file in this directory. Is there a way to enable debugging ? I tried to look at network trafic to port 8100 but I don't see something useful.
Back to top
View user's profile Send private message
probert
General User
General User


Joined: 13 Apr 2006
Posts: 16

PostPosted: Thu Apr 27, 2006 10:40 am    Post subject: Reply with quote

Ok, by opening the CSV path in the SDBC url instead of the directory, it's working, but it's working only when I open the database properties, before that I don't see the table.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group