Bonjour,
je tente de créer une base de données de type texte-CSV à partir de
code Java et j'ai de la difficulté à voir la table. La base de données
(.odb) est créé au bon endroit, mais je ne vois pas de table dans OOo
Base. Par contre, si je vérifie les propriétés de la base de données,
la table apparaît par magie :-/ J'ai cherché en vain sur OOoForum et
il semble que mon problème serait relié aux propriétés de la base, mais
je crois avoir les bonnes :-( Voici mon code (basé sur un code snippet
pour OOo 1.1) :
------------------------------------
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());
xServ.registerObject(mDataSourceName, dataSource);
XPropertySet props = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, dataSource);
props.setPropertyValue("URL", "sdbc:flat:file://" + mDataSourceDir +
"/" + mDataSourceName);
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();
}
}
------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]