Saturday, April 09, 2011

How to Make JBoss App talk to MySql

1. Configuring MySql in JBoss

MySQL is an open source database used by many open source projects and small organizations. To use JBoss 4.0 with MySQL, we first need to put the MySQL driver classes into the CLASSPATH. Copy the .jar file mysql-connector-java-3.0.9-stable-bin.jar to the /server/default/lib directory.

To use the MySQL data source, copy /docs/examples/jca/mysql-ds.xml to the /server/default/deploy directory. Modify the mysql-ds.xml configuration file by setting to com.mysql.jdbc.Driver and to jdbc:mysql:///, where is the MySQL host server and is the MySQL database.

After the file is copied to the Deploy folder, this can be monitored from MBean in JMX Console

Next, we need to set the and elements in the standardjaws.xml or jaws.xml file:

   java:/MySqlDS   mySQL  

We also need to set the and elements in the standardjbosscmp-jdbc.xml or jbosscmp-jdbc.xml file:

             java:/MySqlDS        mySQL    

Finally, we modify login-config.xml with MySQL database settings. Add the following element to login-config.xml:

                     sa          sa                                 jboss.jca:service=LocalTxCM,name=MySqlDS                        

By modifying the mysql-ds.xml, standardjaws.xml, standardjbosscmp-jdbc.xml, and login-config.xml files, the JBoss 4.0 server is configured to be used with a MySQL database.

Files Attached for reference

Click here for more info

2. Programming to talk to MySql in JBoss

No comments: