In the previous section, a JDBC connection was obtained in the Connections navigator. A corresponding JNDI managed data source becomes available for the Connections navigator connection. A data source object is configured with a JNDI Name binding in the OC4J server integrated with JDeveloper. A data source may also be configured in the Embedded OC4J Server Preferences window directly, or may be configured declaratively by modifying the data-sources.xml file. We will discuss each of these methods for creating a data source. A data source may be configured at the Global level or the Current Workspace level. A Global data source is available to all applications while a Current Workspace data source is available only in the current workspace. To create a new Global data source, select Tools | Embedded OC4J Preferences and select the Global | Data Sources node, and click on the New button.
Before we are able to configure a managed data source, we need to configure a connection pool. In the Create Data Source window select Transaction Level as Connection Pool, specify a connection pool name, and click on the OK button.
A new connection pool gets created and its tuning properties may be set, as required. In the Connection Factory window, specify a Factory Class, User name, Password, Login Timeout, and connection URL. The Factory Class is required to implement one of the following interfaces:
- java.sql.Driver,
- javax.sql.DataSource,
- javax.sql.ConnectionPoolDataSource,
- javax.sql.XADataSource.
The Factory Class for a MySQL managed data source can be a MySQL class that implements the javax.sql.DataSource interface, for example the com.mysql.jdbc.jdbc2.optional.MysqlDataSource and com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource classes, or it can be a class that implements the java.sql.Driver interface, for example the com.mysql.jdbc.Driver class. Whether a class implementing the java.sql.Driver interface is used, or a class implementing the javax.sql.DataSource interface is used, the OC4J server wraps the class and provides an implementation of the javax.sql.DataSource interface. We will use the data source class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource. A Password is not required for a root user, by default. Specify the connection URL as
jdbc:mysql://localhost:3306/test.
Click on OK to configure the connection pool.