title: wildfly registering mysql as a datasource
body: <p>I have been trying to configure mysql as a datasource in wildfly. I am not sure what i am missing out, i get an error on startup .</p>
  
  <p>I have the  mysql-connector-java-5.0.8-bin.jar and the  module.xml in the folder: 
  "/wildfly-8.1.0.Final/modules/system/layers/base/com/mysql/main"</p>
  
  <p>below are the files </p>
  
  <p>module.xml</p>
  
  <pre><code>    &lt;module xmlns="urn:jboss:module:1.1" 
          name="com.mysql"&gt;
      &lt;resources&gt;
          &lt;resource-root path="mysql-connector-java-5.0.8.jar"/&gt;
          &lt;!-- Insert resources here --&gt;
      &lt;/resources&gt;
      &lt;dependencies&gt;
          &lt;module name="javax.api"/&gt;
          &lt;module name="javax.transaction.api"/&gt;
          &lt;module name="javax.servlet.api" optional="true"/&gt;
      &lt;/dependencies&gt;
  &lt;/module&gt;
  </code></pre>
  
  <p>standalone.xml</p>
  
  <pre><code>  &lt;datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true"&gt;
      &lt;connection-url&gt;jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE&lt;/connection-url&gt;
      &lt;driver&gt;h2&lt;/driver&gt;
      &lt;security&gt;
        &lt;user-name&gt;sa&lt;/user-name&gt;
        &lt;password&gt;sa&lt;/password&gt;
      &lt;/security&gt;
    &lt;/datasource&gt;
    &lt;datasource jta="true" jndi-name="java:jboss/datasources/proj" pool-name="proj" enabled="true" use-java-context="true" use-ccm="true"&gt;
      &lt;connection-url&gt;jdbc:mysql://localhost:3306&lt;/connection-url&gt;
      &lt;driver&gt;mysql&lt;/driver&gt;
      &lt;security&gt;
        &lt;user-name&gt;root&lt;/user-name&gt;
        &lt;password&gt;admin123&lt;/password&gt;
      &lt;/security&gt;
      &lt;statement&gt;
        &lt;prepared-statement-cache-size&gt;32&lt;/prepared-statement-cache-size&gt;
        &lt;share-prepared-statements&gt;true&lt;/share-prepared-statements&gt;
      &lt;/statement&gt;
    &lt;/datasource&gt;
    &lt;drivers&gt;
      &lt;driver name="mysql" module="com.mysql"&gt;
        &lt;xa-datasource-class&gt;com.mysql.jdbc.jdbc2.optional.MysqlXADataSource&lt;/xa-datasource-class&gt;
      &lt;/driver&gt;
      &lt;driver name="h2" module="com.h2database.h2"&gt;
        &lt;xa-datasource-class&gt;org.h2.jdbcx.JdbcDataSource&lt;/xa-datasource-class&gt;
      &lt;/driver&gt;
    &lt;/drivers&gt;
  &lt;/datasources&gt;
  </code></pre>
  
  <p>I have tested the jdbc connectivity with a standalone program in eclipse and it worked</p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  
  public class ConnectSql {
      public static void main(String []args){
          String userName = "root";
          String pass = "admin123";
          String url = "jdbc:mysql://localhost/";
          String driver ="com.mysql.jdbc.Driver";
          String db = "proj";
  
          try{
              //registering the driver.
              Class.forName(driver);
              Connection con = DriverManager.getConnection(url+db,userName,pass);
              Statement st = con.createStatement();
              ResultSet rs = st.executeQuery("select f_name from t_users");
              while(rs.next()){
                  System.out.println("name :"+rs.getString(1));
              }
  
  
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          catch(ClassNotFoundException cnf){
              cnf.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Referred to the below link and modified the module.xml </p>
  
  <p><a href="https://stackoverflow.com/questions/22120130/wildfly-8-0-0-mysql-problems-with-datasource">Wildfly 8.0.0 mysql problems with datasource</a></p>
  
  <p>Here is a the error log i get on start up</p>
  
  <blockquote>
    <p>02:45:17,169 ERROR [org.jboss.as.controller.management-operation]
    (Controller Boot Thread) JBAS014613: Operation ("add") failed -
    address: ([
        ("subsystem" => "datasources"),
        ("data-source" => "proj") ]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => [
        "jboss.data-source.java:jboss/datasources/proj is missing [jboss.jdbc-driver.mysql]",
        "jboss.driver-demander.java:jboss/datasources/proj is missing [jboss.jdbc-driver.mysql]" ]} 02:45:17,175 ERROR
    [org.jboss.as.controller.management-operation] (Controller Boot
    Thread) JBAS014613: Operation ("add") failed - address: ([
        ("subsystem" => "datasources"),
        ("data-source" => "proj") ]) - failure description: {
        "JBAS014771: Services with missing/unavailable dependencies" => [
            "jboss.data-source.java:jboss/datasources/proj is missing [jboss.jdbc-driver.mysql]",
            "jboss.driver-demander.java:jboss/datasources/proj is missing [jboss.jdbc-driver.mysql]"
        ],
        "JBAS014879: One or more services were unable to start due to one or more indirect dependencies not being available." => {
            "Services that were unable to start:" => [
                "jboss.data-source.reference-factory.proj",
                "jboss.naming.context.java.jboss.datasources.proj"
            ],
            "Services that may be the cause:" => ["jboss.jdbc-driver.mysql"]
        } }</p>
  </blockquote>