title: Error using JNDI datasouce on JBoss 7 for MySQL
body: <p>I followed <a href="https://community.jboss.org/wiki/DataSourceConfigurationInAS7" rel="nofollow noreferrer">these instructions</a>.</p>
  
  <p>I want to connect MySQL database using JNDI dataSource on JBoss to retrieve some data. </p>
  
  <p>Error is generated as soon as I run test.jsp:</p>
  
  <pre><code>javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for java:/jdbc/bookstore"
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
      org.apache.jsp.test_jsp._jspService(test_jsp.java:90)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
  </code></pre>
  
  <p>This is what I got:</p>
  
  <p>MySQL Server 5.5:
      database -> bookstore
      table -> book</p>
  
  <pre><code>connector -&gt; mysql-connector-java-5.1.21-bin.jar
  container -&gt; jboss-as-7.1.1.Final
  IDE -&gt; Eclipse juno
  </code></pre>
  
  <p>STEP 1 - JBoss:</p>
  
  <p>[JBoss_Home]/modules/com/mysql/main -> Got files below</p>
  
  <pre><code>module.xml
  mysql-connector-java-5.1.21-bin.jar
  mysql-connector-java-5.1.21-bin.jar -&gt; this auto created
  </code></pre>
  
  <p>module.xml contains:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;module xmlns="urn:jboss:module:1.0" name="com.mysql"&gt;
    &lt;resources&gt;
      &lt;resource-root path="mysql-connector-java-5.1.21-bin.jar"/&gt;
    &lt;/resources&gt;
    &lt;dependencies&gt;
      &lt;module name="javax.api"/&gt;
    &lt;/dependencies&gt;
  &lt;/module&gt;
  </code></pre>
  
  <p>STEP 2 JBoss:</p>
  
  <p>[JBoss_Home]/standalone/configuration/standalone.xml</p>
  
  <p><code>standalone.xml</code> added dataSource as below:</p>
  
  <pre><code>&lt;subsystem xmlns="urn:jboss:domain:datasources:1.0"&gt;
              &lt;datasources&gt;
                  &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&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:/jdbc/bookstore" pool-name="bookstore_pool" enabled="true" use-java-context="true" use-ccm="true"&gt;
                      &lt;connection-url&gt;jdbc:mysql://localhost:3306/bookstore&lt;/connection-url&gt;
                      &lt;driver&gt;mysql&lt;/driver&gt;
                      &lt;transaction-isolation&gt;TRANSACTION_READ_COMMITTED&lt;/transaction-isolation&gt;
                      &lt;pool&gt;
                          &lt;min-pool-size&gt;10&lt;/min-pool-size&gt;
                          &lt;max-pool-size&gt;100&lt;/max-pool-size&gt;
                          &lt;prefill&gt;true&lt;/prefill&gt;
                      &lt;/pool&gt;
                      &lt;security&gt;
                          &lt;user-name&gt;root&lt;/user-name&gt;
                          &lt;password&gt;786&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;
          &lt;/subsystem&gt;
  </code></pre>
  
  <p><strong>STEP 3 - Eclipse Project:</strong></p>
  
  <p>test.jsp page:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt;
  
  
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  
  &lt;sql:query var="rs" dataSource="java:/jdbc/bookstore"&gt;
  select title,description from book
  &lt;/sql:query&gt;
  
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;DB Test&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
  
    &lt;h2&gt;Results&lt;/h2&gt;
  
  &lt;c:forEach var="row" items="${rs.rows}"&gt;
      Foo ${row.title}&lt;br/&gt;
      Bar ${row.description}&lt;br/&gt;
  &lt;/c:forEach&gt;
  
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Add in <strong>web.xml:</strong></p>
  
  <pre><code>&lt;!-- JDBC DataSources (java:comp/env/jdbc) --&gt;
      &lt;resource-ref&gt;
          &lt;description&gt;The used datasource&lt;/description&gt;
          &lt;res-ref-name&gt;jdbc/bookstore&lt;/res-ref-name&gt;
          &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
          &lt;res-auth&gt;Container&lt;/res-auth&gt;
      &lt;/resource-ref&gt;
  </code></pre>
  
  <p><strong>jboss-web.xml</strong> contains:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jboss-web&gt;
      &lt;resource-ref&gt;
          &lt;res-ref-name&gt;jdbc/bookstore&lt;/res-ref-name&gt;
          &lt;jndi-name&gt;java:/jdbc/bookstore&lt;/jndi-name&gt;
          &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
          &lt;res-auth&gt;Container&lt;/res-auth&gt;
      &lt;/resource-ref&gt;
  &lt;/jboss-web&gt;
  </code></pre>
  
  <p>Below is the project structure:</p>
  
  <p><img src="https://i.stack.imgur.com/CLIcU.gif" alt="Project"></p>