Difference between revisions of "Documentation/DevGuide/Database/Connecting Through a Specific Driver"
From Apache OpenOffice Wiki
< Documentation | DevGuide
m |
OOoWikiBot (Talk | contribs) m (Robot: Changing Category:Database Access) |
||
Line 46: | Line 46: | ||
</source> | </source> | ||
{{PDL1}} | {{PDL1}} | ||
− | [[Category: Database Access]] | + | |
+ | [[Category:Documentation/Developers Guide/Database Access]] |
Revision as of 11:40, 4 June 2008
- 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). |