Difference between revisions of "Documentation/DevGuide/Database/Connecting Through a Specific Driver"
From Apache OpenOffice Wiki
< Documentation | DevGuide
OOoWikiBot (talk | contribs) m (FINAL VERSION FOR L10N) |
m |
||
| Line 10: | Line 10: | ||
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: | 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: | ||
<!--[SOURCE:Database/CodeSamples.java]--> | <!--[SOURCE:Database/CodeSamples.java]--> | ||
| − | + | <syntaxhighlight lang="java"> | |
// create the Driver using the implementation name | // create the Driver using the implementation name | ||
Object aDriver = xMultiServiceFactory.createInstance("com.sun.star.comp.sdbcx.adabas.ODriver"); | Object aDriver = xMultiServiceFactory.createInstance("com.sun.star.comp.sdbcx.adabas.ODriver"); | ||
| Line 45: | Line 45: | ||
} | } | ||
} | } | ||
| − | + | </syntaxhighlight> | |
{{PDL1}} | {{PDL1}} | ||
[[Category:Documentation/Developer's Guide/Database Access]] | [[Category:Documentation/Developer's Guide/Database Access]] | ||
Latest revision as of 14:03, 21 December 2020
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). |