Monday, November 15, 2010

Create a connection pool to MySQL in OC4J

It is quite easy to create a connection pool/datasource to an Oracle database in OAS EM (Enterprise Manager). You simply do that in OC4J > Administration > JDBC Resources. However, it is not that straight forward to do that with a third party database, in my case, MySQL. Basically, you need to provide mySQL jdbc driver and make sure to use the correct parameters.

This is the obscure part. The creation of connection pool/datasource in EM is via the ascontrol application. So we need to let it know how to load mySQL jdbc driver. There are two steps. Firstly, copy mysql-connector-java-5.1.13-bin.jar to
C:\product\10.1.3.1\OracleAS_1\j2ee\home\applications\ascontrol\ascontrol\WEB-INF\lib. Secondly, edit C:\product\10.1.3.1\OracleAS_1\j2ee\home\applications\ascontrol\META-INF\orion-application.xml and comment out the "remove-inherited" section like below.

   <imported-shared-libraries>
<!--
<remove-inherited name="global.libraries"/>
-->
<import-shared-library name="oracle.xml.security"/>
</imported-shared-libraries>



Everything is pretty straight forward after this. To create a connection pool, remember to use "com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource" for "Connection Factory Class" and similar to "jdbc:mysql://localhost:3306/test" for "JDBC URL". You can create a datasource the same way after a connection pool is created.

Reference:
http://forums.oracle.com/forums/thread.jspa?threadID=680574

No comments:

Post a Comment