Connecting Through a Specific Driver

From Apache OpenOffice Wiki
Jump to: navigation, search

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("");
  // query for the XDriver interface 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 [] adabasProps = new[] {
          new"user", 0, "test1",
          new"password", 0, "test1",
      // 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) {
              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).
Personal tools
In other languages