Difference between revisions of "Documentation/DevGuide/Database/Connecting Through a Specific Driver"
From Apache OpenOffice Wiki
< Documentation | DevGuide
OOoWikiBot (Talk | contribs) m (Robot: Changing Category:Database Access) |
m |
||
(2 intermediate revisions by one other user not shown) | |||
Line 6: | Line 6: | ||
|NextPage=Documentation/DevGuide/Database/Driver Specifics | |NextPage=Documentation/DevGuide/Database/Driver Specifics | ||
}} | }} | ||
− | {{DISPLAYTITLE:Connecting Through a Specific Driver}} | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/Database/{{SUBPAGENAME}}}} |
+ | {{DISPLAYTITLE:Connecting Through a Specific Driver}} | ||
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 44: | Line 45: | ||
} | } | ||
} | } | ||
− | + | </syntaxhighlight> | |
{{PDL1}} | {{PDL1}} | ||
− | [[Category:Documentation/ | + | [[Category:Documentation/Developer's Guide/Database Access]] |
Latest revision as of 14:03, 21 December 2020
- Connecting Through a DataSource
- Connecting Using the DriverManager and a Database URL
- Connecting Through a Specific Driver
- Driver Specifics
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). |