Saturday, March 7, 2009

Configuring MySQL for the Sun App Server

Last winter, I took a course on "Designing J2EE Enterprise Applications" at UC Berkeley Extension. While doing the course, though not required, I ended up installing MySQL server and configuring it for the Sun App server. Due to lack of documentation on the configuration, I went through some trial and error but finaly figured out the configuration. Here are the steps:

Installing database server and setting up
Install mysql server
Create a database
Create tables, users as suitable
Install j connector JDBC driver
Add the connector to your system classpath (computer->system->advanced->env variables)
Open admin console of server
Add the jdbc driver (jar fle) to the JVM settings->path settings.

Configuring connection resource in appserver
Open admin console of server
add a new connection pool under resources->connectionPool.
Select new.
Name: enter any name to identify this connection pool. Select javax.sql.DataSource
for resource type. Database Vendor see mysql and select it or select your vendor or leave blank if your vendor do not appear. click next.
Data Source Class Name: enter your class name i.e. Find your database driver name and enter here. For mysql 5.0, it is com.mysql.jdbc.jdbc2.optional.MysqlDataSource
Scroll down to add Properties. Add the following:
user, password, databaseName, port(3306:default), serverName(localhost)
Save.
Now connection pool is created for the database.

Now create the resource
In admin console go to resources->jdbc resources
Add a new jndi name for jdbc resources
Go back to connection pool and ping
Click new.
Enter the JNDI Name you will use to identify the connection pool in your application i.e ejb/customer or anything you want . Select the Pool Name you just configured from the list and click save.
Go back to Connection Pools navaigational link and select your database you configured.
Click ping. If you get errors that means it is not yet working. So try again.

No comments:

Post a Comment