Connecting Through a Specific Driver
From Apache OpenOffice Wiki
< Documentation | DevGuide
The second method to create an independent, data-source connection is to use a particular driver implementation, such as writing a driver. There are also several implementations. Create an instance of the driver and ask it for a connection to decide what driver is used:
// create the Driver using the implementation name
Object aDriver = xMultiServiceFactory.createInstance("com.sun.star.comp.sdbcx.adabas.ODriver");
// query for the XDriver interface
com.sun.star.sdbc.XDriver xDriver;
xDriver = (XDriver)UnoRuntime.queryInterface(XDriver.class, aDriver);
if (xDriver != null) {
// first create the needed url
String adabasURL = "sdbc:adabas::MYDB0";
// second create the necessary properties
com.sun.star.beans.PropertyValue [] adabasProps = new com.sun.star.beans.PropertyValue[] {
new com.sun.star.beans.PropertyValue("user", 0, "test1",
com.sun.star.beans.PropertyState.DIRECT_VALUE),
new com.sun.star.beans.PropertyValue("password", 0, "test1",
com.sun.star.beans.PropertyState.DIRECT_VALUE)
};
// now create a connection to adabas
XConnection adabasConnection = xDriver.connect(adabasURL,adabasProps);
if (xConnection != null) {
System.out.println("Connection was created!");
// now we dispose the connection to close it
XComponent xComponent = (XComponent)UnoRuntime.queryInterface(XComponent.class, xConnection);
if (xComponent != null) {
xComponent.dispose();
System.out.println("Connection disposed!");
}
} else {
System.out.println("Connection could not be created!");
}
}
Content on this page is licensed under the Public Documentation License (PDL). |