Hi Stefan,

you could either use the URL sdbc:mysql:jdbc or you have to add the property "ParameterNameSubstitution" to true. There exists some more properties like "IsAutoRetrievingEnabled" = true and "AutoRetrievingStatement" = "SELECT LAST_INSERT_ID()"

I hope this helps a little bit.

Have a nice day,

Ocke

Stefan wrote:
Hi!
I had put this question already into the oooforum, but unfortunately got no
response yet. Maybe someone of this mailing list can help.

I've the following problem:
I have written a program which automatically creates forms in a Writer
Document. It is basically the same as the form example provided by
OpenOffice.org SDK. It creates a Main-Form and a Sub-Form (the Sub-Form is
implemented with grid-columns). The underlying database is a mysql database.
When I create a connection manually via the Base GUI to this database and
use this registered database in the form-program everything works perfectly.


When I use an automatically created datasource (as the bottom code shows),
which makes so far as a know exactly the same as the manually creation of
the datasouce, the form-program creates the Writer Document without any
errors. BUT when I open the created Writer Document a OpenOffice error pop
up appears, which says:
"The data content could not be loaded. Parameter index out of range (1 >
number of parameters, which is 0)"
This obviously only applies to the Sub-Form because the Main-form works and
in the Sub-Form there are except for the column-headline-labels no columns
in the grid.
I don't think there is a mistake in the from-code because with the manually
created registered database it works. Maybe someone can help me!!
Greets Stefan



Here the code for automatically creating and registering the datasource:

Code:



import com.sun.star.beans.PropertyValue; import com.sun.star.beans.XPropertySet; import com.sun.star.comp.helper.BootstrapException; import com.sun.star.frame.XModel; import com.sun.star.frame.XStorable; import com.sun.star.lang.XSingleServiceFactory; import com.sun.star.sdb.XDocumentDataSource; import com.sun.star.sdb.XOfficeDatabaseDocument; import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XNamingService; import com.sun.star.util.XCloseable; public class d12_2_2_addingDatasource { public static void main(String[] args) { /********* create service factory ******************************/ //get the remote office component context com.sun.star.uno.XComponentContext xContext = null; com.sun.star.lang.XMultiComponentFactory xMCF = null; try { xContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); System.out.println("Connected to a running office ..."); //get the Service Factory xMCF = xContext.getServiceManager(); } catch (BootstrapException e) { e.printStackTrace(); } /***************************************************************/ XSingleServiceFactory xFac= null; Object xDs = null; try { xFac = (XSingleServiceFactory)UnoRuntime.queryInterface( XSingleServiceFactory.class,
xMCF.createInstanceWithContext("com.sun.star.sdb.DatabaseContext",xContext))
; System.out.println("xFac:"+xFac); //instantiate an empty data source at the XSingleServiceFactory //interface of the DatabaseContext xDs = xFac.createInstance(); System.out.println("xDs:"+xDs); XDocumentDataSource xDocumentDataSource = (XDocumentDataSource) UnoRuntime.queryInterface(XDocumentDataSource.class, xDs); XOfficeDatabaseDocument xDatabaseDocument = xDocumentDataSource.getDatabaseDocument(); XStorable store = (XStorable) UnoRuntime.queryInterface( XStorable.class, xDatabaseDocument); XCloseable close = (XCloseable) UnoRuntime.queryInterface( XCloseable.class, xDatabaseDocument); XModel model = (XModel) UnoRuntime.queryInterface( XModel.class, xDatabaseDocument); //register it with the database context XNamingService xServ = (XNamingService)UnoRuntime.queryInterface(XNamingService.class, xFac); System.out.println("xServ:"+xServ); store.storeAsURL("file:///c:/odbfiles/mysqljava5.odb",model.getArgs()); xServ.registerObject("mysqljava5", xDs); //setting the necessary data source properties XPropertySet xDsProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xDs); //Adabas D URL xDsProps.setPropertyValue("URL", "jdbc:mysql://localhost:3306/test"); //force password dialog xDsProps.setPropertyValue("IsPasswordRequired", new Boolean(true)); //suggest dsadmin as user name PropertyValue[] props = new PropertyValue[] { new
com.sun.star.beans.PropertyValue("JavaDriverClass", 0,
"org.gjt.mm.mysql.Driver",com.sun.star.beans.PropertyState.DIRECT_VALUE)}; xDsProps.setPropertyValue("Info", props); xDsProps.setPropertyValue("User", "stefan"); store.store(); close.close(true); System.out.println("END"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }


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

Reply via email to