MySQL Driver Adapter

Usage

The Pax JDBC MySQL Driver Adapter registers a DataSourceFactory in the OSGi service registry, adapting implementation classes of the official MySQL JDBC Driver.

The DataSourceFactory methods of this adapter produces objects with the following implementation classes:

  • com.mysql.jdbc.Driver
  • MysqlDataSource
  • MysqlConnectionPoolDataSource
  • MysqlXADataSource

Service Properties

The MySQL Driver Adapter registers its DataSourceFactory with the following service properties:

  • osgi.jdbc.driver.class = com.mysql.jdbc.Driver
  • osgi.jdbc.driver.name = mysql

Method Arguments

The argument passed to createDataSource(), createConnectionPoolDataSource(), createXADataSource() supports the following properties:

  • DataSourceFactory.JDBC_DATABASE_NAME (mandatory)
  • DataSourceFactory.JDBC_USER
  • DataSourceFactory.JDBC_PASSWORD

An SQLException is thrown if any other properties are set or if a mandatory property is missing.

createDriver()

This method returns an instance of com.mysql.jdbc.Driver. Any properties passed to this method are ignored.

Obtaining a DataSourceFactory

To obtain a DataSourceFactory, use any OSGi service lookup or injection method (Declarative Services, Blueprint) of your choice and specify the following properties:

  • objectClass = org.osgi.service.jdbc.DataSourceFactory

and at least one of

  • osgi.jdbc.driver.class = com.mysql.jdbc.Driver
  • osgi.jdbc.driver.name = mysql

Required Maven Artifacts

  • org.ops4j.pax.jdbc:pax-jdbc-mysql
  • An OSGi-ready version of mysql:mysql-connector-java
  • org.osgi:org.osgi.enterprise:4.2.0
  • An OSGi 4.2 framework