Friday, January 15, 2010

how to setup a mysql data source in Jboss

Download the driver

 

  • First, http://www.mysql.com/products/connector/j/ appropriate for your edition of mySQL. 

  • Next, untar/unzip it and extract the jar file.

  • Copy the jar file into $JBOSS_HOME/server/xxx/lib, where xxx is your config name (such as "default") NOTE: For JBoss 4.0.2, use the jar file mysql-connector-java-3.1.8-bin.jar, not mysql-connector-java-3.1.8-bin-g.jar.

  • Copy the $JBOSS_HOME/docs/examples/jca/mysql-ds.xml file to $JBOSS_HOME/server/xxx/deploy

 

Configure the datasource

 

  • Edit the mysql-ds.xml file.

  • Replace <jndi-name>MySqlDS</jndi-name> with your datasource name.  If you choose to make mySQL your default database (DefaultDS), then call this DefaultDS and be sure to delete the example $JBOSS_HOME/server/all/deploy/hsqldb-ds.xml which is also configured to be DefaultDS.

  • Replace <connection-url>jdbc:mysql://mysql-hostname:3306/jbossdb</connection-url> with your connection string.  Generally you just need to replace mysql-hostname with your host.  Be sure that your user has permission to connect to that hostname.

  • Set the user-name and hostname elements to your database username and hostname

 

Advanced options for the MySQL Driver can be set with <connection-property name="property">value</connection-property>.

Refer to MySQL Connector/J Manual Chapter 2 for more Information.



Source: http://community.jboss.org/wiki/SetUpAMysqlDatasource

No comments: