Web Development

Configure mysql datasource in wildfly 8.0

Add mysql module to wildfly application server:

1. Go to wildfly-8.0.0.Final\modules\system\layers\base\com
2. Create folder like “sql\mysql\main\” and go to sql\mysql\main\
3. Place mysql connector jar to main folder
4. Place module.xml file to main folder

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.sql.mysql">
  <resources>
     <resource-root path="mysql-connector-java-5.0.4-bin.jar"/>              
  </resources>
  <dependencies>
     <module name="javax.api"/>
  </dependencies>
</module>

Add datasource to wildfly configuration file

1. Go to C:\Program Files\wildfly-8.0.0.Final\wildfly-8.0.0.Final\standalone\configuration
2. Open standalone.xml file (we assume you are using standalone.xml as server configuration file)
3. Add following code to datasources section

<datasources>
	<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
		<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
		<driver>h2</driver>
		<security>
			<user-name>sa</user-name>
			<password>sa</password>
		</security>
	</datasource>
	<datasource jndi-name="java:jboss/datasources/brachub" pool-name="brachub" enabled="true" use-java-context="true">
		<connection-url>jdbc:mysql://localhost:3306/brachub</connection-url>
		<driver>mysql</driver>
		<security>
			<user-name>root</user-name>
			<password>1234</password>
		</security>
		<statement>
			<prepared-statement-cache-size>100</prepared-statement-cache-size>
			<share-prepared-statements>true</share-prepared-statements>
		</statement>
	</datasource>
	<drivers>
		<driver name="mysql" module="com.sql.mysql">
			<driver-class>com.mysql.jdbc.Driver</driver-class>
		</driver>
		<driver name="h2" module="com.h2database.h2">
			<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
		</driver>
	</drivers>
</datasources>

Hope this will work.

Advertisements

6 thoughts on “Configure mysql datasource in wildfly 8.0

  1. I think I tried above setting and this version of the my sql actually doesnt work well with the wild fly 8.1.0 it never worked for me. I had to download the latest version to solve the issue. but it is good sample for the configuration need to be done for the mysql connector. or jdbc driver.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s