<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Error using JNDI datasouce on JBoss 7 for MySQL
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/prashid">Pirzada Rashid</a> in <i>JNDI and Naming</i> - <a href="https://community.jboss.org/message/746991#746991">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p><span>I have spent many hrs try to fix the problem but no success. Googled and raed many related articles. followed this </span><a class="jive-link-external-small" href="https://community.jboss.org/docs/DOC-16657" target="_blank">https://community.jboss.org/wiki/DataSourceConfigurationInAS7</a><span> also.</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I want to connect MySQL database using JNDI dataSource on JBoss to reterive some data. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Someone please help.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="color: #ff0000;"><strong>Error is generated as soon as I run test.jsp:</strong></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for java:/jdbc/bookstore"</p><p>        org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)</p><p>        org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)</p><p>        org.apache.jsp.test_jsp._jspService(test_jsp.java:90)</p><p>        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)</p><p>        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)</p><p>        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)</p><p>        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)</p><p>        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)</p><p>        javax.servlet.http.HttpServlet.service(HttpServlet.java:847)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><em><strong>This is what I got</strong></em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>MySQL Server 5.5:</p><p>    database -> bookstore</p><p>    table -> book</p><p>    </p><p>    connector -> mysql-connector-java-5.1.21-bin.jar</p><p>    container -> jboss-as-7.1.1.Final</p><p>    IDE -> Eclipse juno</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h3>STEP 1 - JBoss:</h3><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>[JBoss_Home]/modules/com/mysql/main -> Got files below</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    module.xml</p><p>    mysql-connector-java-5.1.21-bin.jar</p><p>    mysql-connector-java-5.1.21-bin.jar -> this auto created</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h5>module.xml contain:</h5><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    <?xml version="1.0" encoding="UTF-8"?></p><p>    <module xmlns="urn:jboss:module:1.0" name="com.mysql"></p><p>      <resources></p><p>        <resource-root path="mysql-connector-java-5.1.21-bin.jar"/></p><p>      </resources></p><p>      <dependencies></p><p>        <module name="javax.api"/></p><p>      </dependencies></p><p>    </module></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h3>STEP 2 JBoss:</h3><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>[JBoss_Home]/standalone/configuration/standalone.xml</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h5>standalone.xml added dataSource as below:</h5><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    <subsystem xmlns="urn:jboss:domain:datasources:1.0"></p><p>                <datasources></p><p>                    <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true"></p><p>                        <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url></p><p>                        <driver>h2</driver></p><p>                        <security></p><p>                            <user-name>sa</user-name></p><p>                            <password>sa</password></p><p>                        </security></p><p>                    </datasource></p><p>                    <datasource jta="true" jndi-name="java:/jdbc/bookstore" pool-name="bookstore_pool" enabled="true" use-java-context="true" use-ccm="true"></p><p>                        <connection-url>jdbc:mysql://localhost:3306/bookstore</connection-url></p><p>                        <driver>mysql</driver></p><p>                        <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation></p><p>                        <pool></p><p>                            <min-pool-size>10</min-pool-size></p><p>                            <max-pool-size>100</max-pool-size></p><p>                            <prefill>true</prefill></p><p>                        </pool></p><p>                        <security></p><p>                            <user-name>root</user-name></p><p>                            <password>786</password></p><p>                        </security></p><p>                        <statement></p><p>                            <prepared-statement-cache-size>32</prepared-statement-cache-size></p><p>                            <share-prepared-statements>true</share-prepared-statements></p><p>                        </statement></p><p>                    </datasource></p><p>                    <drivers></p><p>                        <driver name="mysql" module="com.mysql"></p><p>                            <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class></p><p>                        </driver></p><p>                        <driver name="h2" module="com.h2database.h2"></p><p>                            <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class></p><p>                        </driver></p><p>                    </drivers></p><p>                </datasources></p><p>            </subsystem></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h3>STEP 3 - Eclipse Project:</h3><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h5>test.jsp page:</h5><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%></p><p>        </p><p>    </p><p><span>    <%@ taglib uri="</span><a class="jive-link-external-small" href="http://java.sun.com/jsp/jstl/sql" target="_blank">http://java.sun.com/jsp/jstl/sql</a><span>" prefix="sql" %></span></p><p><span>    <%@ taglib uri="</span><a class="jive-link-external-small" href="http://java.sun.com/jsp/jstl/core" target="_blank">http://java.sun.com/jsp/jstl/core</a><span>" prefix="c" %></span></p><p>    </p><p>    <sql:query var="rs" dataSource="java:/jdbc/bookstore"></p><p>    select title,description from book</p><p>    </sql:query></p><p>    </p><p>    <html></p><p>      <head></p><p>        <title>DB Test</title></p><p>      </head></p><p>      <body></p><p>    </p><p>      <h2>Results</h2></p><p>      </p><p>    <c:forEach var="row" items="${rs.rows}"></p><p>        Foo ${row.title}<br/></p><p>        Bar ${row.description}<br/></p><p>    </c:forEach></p><p>    </p><p>      </body></p><p>    </html></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h5>Add in web.xml:</h5><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    <!-- JDBC DataSources (java:comp/env/jdbc) --></p><p>        <resource-ref></p><p>            <description>The used datasource</description></p><p>            <res-ref-name>jdbc/bookstore</res-ref-name></p><p>            <res-type>javax.sql.DataSource</res-type></p><p>            <res-auth>Container</res-auth></p><p>        </resource-ref></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h5>jboss-web.xml contains:</h5><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    <?xml version="1.0" encoding="UTF-8"?></p><p>    <jboss-web></p><p>        <resource-ref></p><p>            <res-ref-name>jdbc/bookstore</res-ref-name></p><p>            <jndi-name>java:/jdbc/bookstore</jndi-name></p><p>            <res-type>javax.sql.DataSource</res-type></p><p>            <res-auth>Container</res-auth></p><p>        </resource-ref></p><p>    </jboss-web></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><em><strong>Below is the project structure:</strong></em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><a href="https://community.jboss.org/servlet/JiveServlet/showImage/2-746991-18963/pro.gif"><span> https://community.jboss.org/servlet/JiveServlet/downloadImage/2-746991-18963/303-600/pro.gif </span></a></p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/746991#746991">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JNDI and Naming at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>